@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --teal: #0D9488;
  --teal-light: #14B8A6;
  --teal-dark: #0F766E;
  --navy: #0F172A;
  --navy-mid: #1E293B;
  --navy-light: #334155;
  --white: #FFFFFF;
  --gray: #F1F5F9;
  --gray-mid: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

.area-wrap {
  font-family: 'Inter', sans-serif;
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.area-header {
  background: linear-gradient(135deg, var(--navy), var(--navy-mid));
  color: white;
  padding: 40px;
  border-radius: 16px;
  text-align: center;
  margin-bottom: 20px;
}
.area-header-icon { font-size: 48px; margin-bottom: 10px; }
.area-header h2 { font-size: 30px; font-weight: 800; margin-bottom: 6px; }
.area-header p { opacity: 0.7; font-size: 15px; }

/* Unit Bar */
.area-unit-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.area-unit-label { font-weight: 600; color: var(--navy); font-size: 14px; }
.area-unit-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.area-wrap .area-unit-btn {
  padding: 8px 16px;
  border: 2px solid var(--gray-mid);
  border-radius: 8px;
  background: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted) !important;
  transition: all 0.2s;
}
.area-wrap .area-unit-btn.active, .area-wrap .area-unit-btn:hover {
  background: var(--teal);
  color: white !important;
  border-color: var(--teal);
}

/* Shape Grid */
.area-shapes-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
/*
 * Every color/background on .area-shape-btn (and the other interactive
 * controls below) is pinned with !important and re-declared on :hover
 * rather than left to inherit. Two separate bugs on this site turned out
 * to be the same root cause: some theme rule elsewhere on the page (e.g.
 * a generic `button:hover { color: #fff }` reset) has higher or equal
 * CSS specificity and silently wins the cascade, so text disappears
 * against this widget's light backgrounds. Pinning color explicitly in
 * every state — not just the default state — closes that off for good
 * instead of chasing it state-by-state.
 */
.area-wrap .area-shape-btn {
  background: white;
  border: 2px solid var(--gray-mid);
  border-radius: 12px;
  padding: 14px 8px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--navy) !important;
}
.area-wrap .area-shape-btn:hover {
  border-color: var(--teal);
  background: rgba(13,148,136,0.05);
  color: var(--navy) !important;
}
.area-wrap .area-shape-btn.active,
.area-wrap .area-shape-btn.active:hover {
  border-color: var(--teal);
  background: var(--teal);
  color: white !important;
}
.area-shape-icon { font-size: 22px; }
.area-wrap .area-shape-btn span { font-size: 11px; font-weight: 600; color: inherit !important; }

/* Calc Panel */
.area-calc-panel {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

/* Input Side */
.area-input-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.area-shape-display {
  background: var(--navy);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 200px;
}
#areaCanvas { display: block; cursor: default; }
.area-shape-display.area-drawing-mode #areaCanvas { cursor: crosshair; }

/* Fields */
.area-fields { display: flex; flex-direction: column; gap: 12px; }
.area-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.area-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.area-field-row {
  display: flex;
  align-items: center;
  border: 2px solid var(--gray-mid);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.area-field-row:focus-within { border-color: var(--teal); }
.area-field-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  min-width: 0;
}
.area-field-unit {
  background: var(--gray);
  padding: 12px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal);
  white-space: nowrap;
}
.area-field-unit-select {
  background: var(--gray);
  border: none;
  padding: 12px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal) !important;
  font-family: inherit;
  cursor: pointer;
}

.area-wrap .area-calc-btn {
  background: var(--teal);
  color: white !important;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}
.area-wrap .area-calc-btn:hover { background: var(--teal-dark); color: white !important; }
.area-wrap .area-reset-btn {
  background: white;
  color: var(--navy) !important;
  border: 2px solid var(--gray-mid);
  padding: 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s;
}
.area-wrap .area-reset-btn:hover { border-color: var(--teal); color: var(--teal) !important; }
.area-calc-action-row { display: flex; flex-direction: column; gap: 10px; }

/* Freeform drawing controls */
.area-draw-controls {
  display: none;
  flex-direction: column;
  gap: 12px;
}
.area-draw-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.area-undo-redo-row {
  display: flex;
  gap: 8px;
}
.area-undo-redo-row .area-reset-btn { flex: 1; }
/* This class is used in two places: once inside .area-draw-controls
   (already display:none by default via its parent, so the class's own
   display:flex is fine there) and once as a standalone row right under
   the canvas (#areaCanvasUndoRedo) which has no hidden parent to rely on
   and needs its own default-hidden state, toggled by JS same as the rest
   of the Draw Custom controls. */
#areaCanvasUndoRedo { display: none; }
.area-draw-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
.area-draw-edges {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 140px;
  overflow-y: auto;
}
.area-edge-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-muted) !important;
  background: var(--gray);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  transition: border-color 0.15s, background 0.15s;
}
.area-edge-item-label { font-weight: 700; color: var(--text-muted) !important; }
/* The input, its unit, and the delete button get their own row below the
   label — splitting the label onto its own line (rather than cramming
   "Line N:" + input + unit + delete all on one line) is what actually
   gives the number field enough width to show its full value. */
.area-edge-item-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
/* The wraparound (closing) edge, once a shape is closed, renders as a
   single-line clickable <button> (to locate it on the canvas) instead of
   the multi-row <div> used for editable edges — reset to a row so its
   text + <strong> value flow inline rather than stacking like the column
   layout above, and reset the rest of the button chrome to match. */
button.area-edge-item {
  cursor: pointer;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}
button.area-edge-item:hover { border-color: var(--teal); background: white; }
.area-edge-item-active {
  background: rgba(255, 209, 102, 0.25) !important;
  border-color: var(--teal-light) !important;
}
.area-edge-item strong { color: var(--navy) !important; }
.area-edge-input {
  flex: 1;
  min-width: 0;
  width: auto;
  border: 1px solid var(--gray-mid);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy) !important;
  font-family: inherit;
}
.area-edge-item-unit {
  font-size: 12px;
  color: var(--text-muted) !important;
  white-space: nowrap;
}
.area-edge-delete {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--gray-mid);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 12px;
  color: var(--text-muted) !important;
  cursor: pointer;
}
.area-edge-delete:hover { border-color: #ef4444; color: #ef4444 !important; background: #fef2f2; }

/* Result Side */
.area-result-side { display: flex; flex-direction: column; gap: 16px; }

.area-result-hero {
  background: linear-gradient(135deg, var(--navy), var(--navy-mid));
  color: white;
  border-radius: 16px;
  padding: 36px;
  text-align: center;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.area-result-icon { font-size: 36px; }
.area-result-label { font-size: 13px; opacity: 0.7; text-transform: uppercase; letter-spacing: 1px; }
.area-result-val { font-size: 44px; font-weight: 800; color: var(--teal-light); }
.area-result-unit { font-size: 14px; opacity: 0.6; }
.area-result-unit-select {
  margin-top: 6px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.area-result-unit-select option { color: var(--navy); }

/* Conversions */
.area-conversions, .area-formula-card, .area-history-panel {
  background: white;
  border: 1px solid var(--gray-mid);
  border-radius: 14px;
  padding: 20px;
}
.area-section-title { font-size: 15px; font-weight: 700; color: var(--navy); margin-bottom: 14px; }

.area-conv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.area-conv-item {
  background: var(--gray);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.area-conv-val { font-size: 15px; font-weight: 700; color: var(--teal); }
.area-conv-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.area-formula-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  background: var(--gray);
  padding: 14px;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  line-height: 1.6;
}

/* Export */
.area-export-bar { display: flex; flex-wrap: wrap; gap: 10px; }
.area-wrap .area-export-btn {
  flex: 1 1 auto;
  min-width: 90px;
  background: var(--navy);
  color: white !important;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.area-wrap .area-export-btn:hover { background: var(--teal); color: white !important; }

/* History */
.area-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.area-history-head-actions { display: flex; gap: 8px; }
.area-history-head-actions .area-export-btn { flex: 0 0 auto; padding: 8px 12px; }
.area-history-list { display: flex; flex-direction: column; gap: 10px; }
.area-history-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--gray);
  border: 1px solid var(--gray-mid);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--navy) !important;
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s;
}
.area-history-item:hover { border-color: var(--teal); background: white; color: var(--navy) !important; }
.area-history-item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.area-history-item-summary { font-size: 12.5px; color: var(--text-muted); margin-bottom: 3px; }
.area-history-item-result { font-size: 14px; font-weight: 700; color: var(--teal); }
.area-history-empty {
  display: none;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Native print-to-PDF (see script's areaPrintHtml()) ---------- */
.area-print-area { display: none; }
@media print {
  body.area-printing > *:not(.area-print-area) {
    visibility: hidden !important;
  }
  body.area-printing .area-print-area {
    display: block !important;
    visibility: visible !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  body.area-printing .area-print-area * {
    visibility: visible !important;
  }
  .area-print-area {
    font-family: 'Inter', Arial, sans-serif;
    color: #0F172A;
    padding: 24px;
  }
  .area-print-area h1 {
    font-size: 22px;
    color: #0F172A;
    margin: 0 0 4px;
  }
  .area-print-area .area-print-meta {
    font-size: 11px;
    color: #64748B;
    margin-bottom: 18px;
  }
  .area-print-area h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #0D9488;
    border-bottom: 1px solid #E2E8F0;
    padding-bottom: 4px;
    margin: 18px 0 10px;
  }
  .area-print-area .area-print-highlight {
    background: #F0FDFA;
    border: 1px solid #0D9488;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 16px;
  }
  .area-print-area .area-print-highlight .area-print-big {
    font-size: 22px;
    font-weight: 800;
    color: #0D9488;
  }
  .area-print-area .area-print-entry {
    page-break-inside: avoid;
    border-bottom: 1px dashed #E2E8F0;
    padding: 8px 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .area-shapes-grid { grid-template-columns: repeat(4, 1fr); }
  .area-calc-panel { grid-template-columns: 1fr; }
  .area-conv-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .area-shapes-grid { grid-template-columns: repeat(3, 1fr); }
}
