/* =============================================================================
   styles.css
   All visual styles. Edit the :root variables at the top to change colours,
   fonts, and spacing globally. Sections are clearly labelled.
   ============================================================================= */

/* =============================================================================
   1. DESIGN TOKENS — Edit these to change the look globally
   ============================================================================= */

:root {
  /* Colours */
  --bg:            #f5f4f0;     /* Page background */
  --surface:       #ffffff;     /* Card / sidebar background */
  --surface2:      #f0efe9;     /* Subtle tinted surface */
  --border:        #e2e0d8;     /* Default borders */
  --text:          #1a1a18;     /* Primary text */
  --text2:         #6b6a64;     /* Secondary / label text */
  --text3:         #9b9a94;     /* Hint / placeholder text */

  --accent:        #2d6a4f;     /* Primary colour (green) */
  --accent-light:  #e8f4ee;     /* Light tint of accent */
  --accent2:       #1b4332;     /* Darker accent for hover */

  --inp-bg:        #fffef5;     /* Input field background */
  --inp-border:    #d4c97a;     /* Input field border (yellow) */
  --drp-bg:        #f5f3ff;     /* Dropdown background (purple) */
  --drp-border:    #c4b5fd;     /* Dropdown border */
  --res-bg:        #edf7f1;     /* Result box background (green) */
  --res-border:    #a8d5ba;     /* Result box border */

  --warn:          #e63946;     /* Warning text colour */
  --warn-bg:       #ffeef0;     /* Warning box background */
  --warn-border:   #ffcccc;     /* Warning box border */

  /* Spacing & shape */
  --radius:        14px;        /* Card corner radius */
  --radius-sm:     8px;         /* Input / small element radius */
  --shadow:        0 2px 12px rgba(0,0,0,0.07);

  /* Typography */
  --font:          'DM Sans', sans-serif;
  --mono:          'DM Mono', monospace;

  /* Layout */
  --sidebar-w:     240px;
  --topbar-h:      56px;
}

/* =============================================================================
   2. RESET & BASE
   ============================================================================= */

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* =============================================================================
   3. PASSWORD SCREEN
   ============================================================================= */

#pw-screen {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
#pw-screen .pw-logo    { font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: 40px; }
#pw-screen h1          { font-size: 26px; font-weight: 600; margin-bottom: 8px; text-align: center; }
#pw-screen .pw-sub     { font-size: 14px; color: var(--text2); text-align: center; margin-bottom: 32px; }
#pw-form               { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
#pw-input              { width: 100%; padding: 16px; font-size: 16px; font-family: var(--mono); border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); outline: none; text-align: center; letter-spacing: 0.15em; transition: border-color 0.2s; }
#pw-input:focus        { border-color: var(--accent); }
#pw-btn                { padding: 16px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: background 0.2s; }
#pw-btn:hover          { background: var(--accent2); }
#pw-error              { font-size: 13px; color: var(--warn); text-align: center; min-height: 18px; }

/* =============================================================================
   4. APP SHELL
   ============================================================================= */

#app                   { display: none; min-height: 100dvh; }
#app.visible           { display: block; }
.app-layout            { display: flex; min-height: 100dvh; }

/* =============================================================================
   5. MOBILE TOP BAR
   ============================================================================= */

.topbar                { position: sticky; top: 0; z-index: 100; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 16px; height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; box-shadow: 0 1px 8px rgba(0,0,0,0.06); }
.topbar-title          { font-size: 15px; font-weight: 600; }
.topbar-logo           { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.back-btn              { display: none; align-items: center; gap: 6px; background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 500; font-family: var(--font); cursor: pointer; padding: 8px 0; }
.back-btn svg          { width: 18px; height: 18px; }
.back-btn.visible      { display: flex; }

/* =============================================================================
   6. DESKTOP SIDEBAR (hidden on mobile)
   ============================================================================= */

.sidebar               { display: none; }

/* =============================================================================
   7. MAIN CONTENT AREA
   ============================================================================= */

.main                  { flex: 1; overflow-y: auto; min-width: 0; }

/* =============================================================================
   8. HOME MENU
   ============================================================================= */

#home                  { padding: 24px 16px; }
.home-header           { margin-bottom: 28px; }
.home-header h2        { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.home-header p         { font-size: 14px; color: var(--text2); line-height: 1.5; }

.menu-grid             { display: flex; flex-direction: column; gap: 12px; }
.menu-card             { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px; cursor: pointer; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow); transition: all 0.18s; }
.menu-card:hover       { border-color: var(--accent); box-shadow: 0 4px 20px rgba(45,106,79,0.12); }
.menu-card:active      { transform: scale(0.98); }
.menu-icon             { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-light); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.menu-icon svg         { width: 24px; height: 24px; color: var(--accent); }
.menu-card-text h3     { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.menu-card-text p      { font-size: 13px; color: var(--text2); line-height: 1.4; }
.menu-arrow            { margin-left: auto; color: var(--text3); flex-shrink: 0; }

.disclaimer            { margin-top: 28px; padding: 14px 16px; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); font-size: 12px; color: #7a2020; line-height: 1.6; }

/* =============================================================================
   9. SECTIONS
   ============================================================================= */

.section               { display: none; padding: 16px; }
.section.active        { display: block; }

/* =============================================================================
   10. CARDS
   ============================================================================= */

.card                  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-title            { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

/* =============================================================================
   11. FORM FIELDS
   ============================================================================= */

.field                 { margin-bottom: 14px; }
.field:last-child      { margin-bottom: 0; }
.field label           { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.field-row             { display: flex; gap: 10px; }
.field-row .field      { flex: 1; margin-bottom: 0; }

input[type=number], input[type=text], select {
  width: 100%; padding: 13px 14px; font-size: 16px; font-family: var(--font);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--inp-bg); color: var(--text); outline: none;
  transition: border-color 0.2s; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus  { border-color: var(--accent); }
.inp                       { border-color: var(--inp-border) !important; }           /* yellow = user types */
.drp                       { background: var(--drp-bg) !important; border-color: var(--drp-border) !important; } /* purple = dropdown */
select                     { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6a64' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* =============================================================================
   12. RESULT DISPLAY
   ============================================================================= */

.result-box            { background: var(--res-bg); border: 1.5px solid var(--res-border); border-radius: var(--radius-sm); padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.result-label          { font-size: 13px; color: var(--accent2); font-weight: 500; }
.result-value          { font-size: 20px; font-weight: 600; font-family: var(--mono); color: var(--accent2); }
.result-unit           { font-size: 12px; color: var(--accent); margin-left: 4px; }

.result-row            { display: flex; gap: 10px; margin-bottom: 10px; }
.result-pill           { flex: 1; background: var(--res-bg); border: 1.5px solid var(--res-border); border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; }
.result-pill .rp-lbl   { font-size: 11px; color: var(--accent2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.result-pill .rp-val   { font-size: 18px; font-weight: 600; font-family: var(--mono); color: var(--accent2); }
.result-pill .rp-unit  { font-size: 11px; color: var(--text3); }

/* =============================================================================
   13. WARNINGS
   ============================================================================= */

.warn-box              { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; color: var(--warn); font-weight: 500; margin-top: 8px; }

/* =============================================================================
   14. LED DRUG ROWS
   ============================================================================= */

.drug-row              { background: var(--surface2); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--border); }

/* Row 1: toggle + name input + result + remove */
.drug-row-header       { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.drug-name-input       { flex: 1; padding: 6px 10px; font-size: 13px; font-weight: 500; font-family: var(--font); border: none; background: transparent; color: var(--text); outline: none; min-width: 0; }
.drug-name-input::placeholder { color: rgba(155,154,148,0.45); }
.drug-row-result       { font-size: 13px; font-weight: 600; font-family: var(--mono); color: var(--accent); white-space: nowrap; }
.remove-btn            { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 2px; transition: color 0.15s; flex-shrink: 0; }
.remove-btn:hover      { color: var(--warn); }

/* Row 2: LD/dose + doses/day + formulation */
.drug-core-row         { display: flex; gap: 8px; margin-bottom: 6px; }
.drug-core-field       { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.drug-core-field--narrow { flex: 1; min-width: 80px; }
.drug-core-field label { font-size: 11px; font-weight: 500; color: var(--text3); letter-spacing: 0.02em; white-space: nowrap; }
.drug-core-field input,
.drug-core-field select { padding: 8px 10px; font-size: 14px; }
.drug-core-field select { padding-right: 28px; background-position: right 8px center; }
.drug-core-field input::placeholder { color: rgba(155,154,148,0.4); }

/* Row 3: override factor */
.drug-override-row     { display: flex; align-items: center; gap: 8px; }
.drug-override-label   { font-size: 11px; color: var(--text3); white-space: nowrap; flex-shrink: 0; }
.drug-override-input   { flex: 1; padding: 6px 10px !important; font-size: 13px !important; max-width: 180px; }
.drug-override-input::placeholder { color: rgba(155,154,148,0.4); font-size: 12px; }

/* Add button */
.add-btn               { width: 100%; padding: 11px; background: none; border: 1.5px dashed var(--border); border-radius: var(--radius-sm); color: var(--accent); font-size: 14px; font-weight: 500; font-family: var(--font); cursor: pointer; transition: all 0.18s; margin-top: 4px; }
.add-btn:hover         { background: var(--accent-light); border-color: var(--accent); }

/* =============================================================================
   15. WEAN STEP TABLE
   ============================================================================= */

.step-table            { width: 100%; border-collapse: collapse; font-size: 13px; }
.step-table th         { text-align: left; font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.step-table td         { padding: 10px 8px; border-bottom: 1px solid var(--surface2); font-family: var(--mono); }
.step-table tr:last-child td { border-bottom: none; }
.step-table tr:hover td      { background: var(--surface2); }
.step-table .step-label      { font-family: var(--font); font-weight: 600; color: var(--text2); font-size: 12px; }
.step-table .hl              { color: var(--accent); font-weight: 600; }

/* =============================================================================
   16. TOGGLE SWITCH
   ============================================================================= */

.toggle                { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input          { opacity: 0; width: 0; height: 0; }
.toggle-slider         { position: absolute; inset: 0; background: var(--border); border-radius: 13px; cursor: pointer; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
.toggle input:checked + .toggle-slider             { background: var(--accent); }
.toggle input:checked + .toggle-slider::before     { transform: translateX(18px); }

/* =============================================================================
   17. MISC UTILITIES
   ============================================================================= */

.divider               { height: 1px; background: var(--border); margin: 16px 0; }
.hint                  { font-size: 12px; color: var(--text3); margin-top: 5px; }
.hint-inline           { font-size: 11px; color: var(--text3); font-weight: 400; }

.link-banner           { background: var(--accent-light); border: 1px solid var(--res-border); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; color: var(--accent2); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

.section-note          { font-size: 12px; color: var(--text3); font-style: italic; margin-bottom: 12px; }

.pb-safe               { height: env(safe-area-inset-bottom, 16px); }

/* =============================================================================
   18b. COMPACT INLINE LAYOUT — shared across Starting Dose & Dose Adjustment
   ============================================================================= */

/* Inline result + field side by side (Step 1, Step 3) */
.inline-row            { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.inline-result         { display: flex; align-items: baseline; gap: 6px; flex: 1; min-width: 140px; }
.inline-field          { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 100px; }
.inline-label          { font-size: 11px; font-weight: 500; color: var(--text3); white-space: nowrap; }
.inline-value          { font-size: 22px; font-weight: 600; font-family: var(--mono); color: var(--accent2); }
.inline-unit           { font-size: 12px; color: var(--accent); }

/* Compact input — shorter height for secondary fields */
.compact-inp           { padding: 8px 12px !important; font-size: 15px !important; }
.compact-inp::placeholder { color: rgba(155,154,148,0.4); }

/* Override row — quiet secondary row for non-primary inputs */
.override-row          { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.override-label        { font-size: 11px; color: var(--text3); white-space: nowrap; flex-shrink: 0; min-width: 130px; }
.override-inp          { flex: 1; max-width: 160px; padding: 6px 10px !important; font-size: 13px !important; }
.override-inp::placeholder { color: rgba(155,154,148,0.4); font-size: 12px; }
.override-unit         { font-size: 12px; color: var(--text3); flex-shrink: 0; }

/* HR/LR adj row — label + value input + units dropdown + hint all on one line */
.adj-row               { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.adj-row-label         { font-size: 12px; font-weight: 600; color: var(--text2); width: 24px; flex-shrink: 0; }
.adj-val-inp           { width: 72px !important; flex-shrink: 0; padding: 8px 10px !important; font-size: 14px !important; text-align: center; }
.adj-val-inp::placeholder { color: rgba(155,154,148,0.4); }
.adj-unit-sel          { width: 80px !important; flex-shrink: 0; padding: 8px 28px 8px 10px !important; font-size: 13px !important; }
.adj-row-hint          { font-size: 11px; color: var(--text3); }

/* Rate row — BR/HR/LR label + rate input + separator + hours input + unit */
.rate-row              { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rate-row-label        { font-size: 12px; font-weight: 600; color: var(--text2); width: 24px; flex-shrink: 0; }
.rate-inp              { flex: 1; min-width: 0; padding: 8px 10px !important; font-size: 14px !important; }
.rate-inp::placeholder { color: rgba(155,154,148,0.4); }
.rate-row-sep          { font-size: 11px; color: var(--text3); white-space: nowrap; flex-shrink: 0; }
.hours-inp             { width: 56px !important; flex-shrink: 0; padding: 8px 8px !important; font-size: 14px !important; text-align: center; }
.rate-row-unit         { font-size: 11px; color: var(--text3); flex-shrink: 0; }

/* Hours row — three compact cells for BR/HR/LR hours */
.hours-row             { display: flex; gap: 10px; margin-bottom: 8px; }
.hours-cell            { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.hours-label           { font-size: 11px; font-weight: 500; color: var(--text3); }

/* Mini result — inline calculated value (DA LD-eq) */
.mini-result           { display: flex; align-items: baseline; gap: 4px; padding: 8px 0; }
.mini-result span:first-child { font-size: 18px; font-weight: 600; font-family: var(--mono); color: var(--accent2); }
.mini-result-unit      { font-size: 11px; color: var(--accent); }

/* =============================================================================
   18. DESKTOP LAYOUT — 768px and wider
   ============================================================================= */

@media (min-width: 768px) {

  /* Hide mobile top bar */
  .topbar  { display: none; }
  .pb-safe { display: none; }

  /* Show sidebar */
  .sidebar {
    display: flex; flex-direction: column;
    width: var(--sidebar-w); min-height: 100dvh;
    background: var(--surface); border-right: 1px solid var(--border);
    position: sticky; top: 0; height: 100dvh;
    flex-shrink: 0; overflow-y: auto;
  }
  .sidebar-logo        { padding: 24px 20px 20px; border-bottom: 1px solid var(--border); }
  .sidebar-org         { font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
  .sidebar-title       { font-size: 14px; font-weight: 600; color: var(--text); margin-top: 4px; line-height: 1.3; }
  .sidebar-nav         { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
  .sidebar-nav-item    { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; border: none; background: none; font-family: var(--font); font-size: 14px; font-weight: 500; color: var(--text2); width: 100%; text-align: left; transition: all 0.15s; }
  .sidebar-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text3); transition: color 0.15s; }
  .sidebar-nav-item:hover        { background: var(--surface2); color: var(--text); }
  .sidebar-nav-item:hover svg    { color: var(--accent); }
  .sidebar-nav-item.active       { background: var(--accent-light); color: var(--accent2); font-weight: 600; }
  .sidebar-nav-item.active svg   { color: var(--accent); }
  .sidebar-footer      { padding: 16px 20px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text3); line-height: 1.6; }

  /* Content area */
  .main                { max-width: 800px; }
  #home                { padding: 40px; }
  .section             { padding: 40px; }
  .card                { padding: 24px; }

  /* Home: 3-column menu grid */
  .home-header h2      { font-size: 26px; }
  .menu-grid           { flex-direction: row; }
  .menu-card           { flex-direction: column; align-items: flex-start; gap: 14px; padding: 24px; }
  .menu-arrow          { display: none; }
  .menu-card-text p    { font-size: 12px; }

  /* Larger result numbers */
  .result-value        { font-size: 24px; }
  .result-pill .rp-val { font-size: 22px; }

  /* Step table */
  .step-table          { font-size: 14px; }
  .step-table td       { padding: 12px 10px; }
}

@media (min-width: 1100px) {
  :root { --sidebar-w: 260px; }
  .main { max-width: 880px; }
  #home, .section { padding: 48px; }
}
