/* ==========================================================================
   CRM Theme — single source of truth for look & feel.
   Every page in this app links this file and uses these variables only.
   Change a value here to restyle the whole app at once.
   ========================================================================== */

:root {
  /* ---- Fonts ---- */
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --fs-xs:   12px;   /* fine print, timestamps */
  --fs-sm:   14px;   /* secondary text, labels */
  --fs-base: 16px;   /* body text, form inputs */
  --fs-md:   18px;   /* card titles */
  --fs-lg:   22px;   /* section headings */
  --fs-xl:   28px;   /* page titles */
  --fs-xxl:  34px;   /* dashboard numbers / big stats */

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-bold:   700;

  --lh-tight:  1.2;
  --lh-normal: 1.5;

  /* ---- Colours: base (warm cream, premium real-estate feel) ---- */
  --bg:          #F6F4EE;   /* page background */
  --bg-raised:   #FFFFFF;   /* cards, sheets, modals */
  --bg-sunken:   #F0EDE4;   /* input fields, nested panels */
  --border:      #E4DFD1;
  --border-soft: #EDE9DE;

  /* ---- Colours: text ---- */
  --text:          #121B2E;   /* primary text */
  --text-muted:    #596277;   /* secondary text */
  --text-faint:    #95A0B0;   /* placeholders, disabled */
  --text-on-brand: #FFFFFF;   /* text sitting on --brand */

  /* ---- Colours: brand — deep navy + gold ---- */
  --brand:        #0F2A4C;   /* deep navy — primary buttons, nav, headers */
  --brand-dark:   #081A30;
  --brand-2:      #1B4A7A;   /* lighter navy, for gradients */
  --brand-light:  #E8EDF4;   /* tinted backgrounds, selected rows */
  --accent:       #C8992F;   /* warm gold — CTAs, highlights, "important" flag */
  --accent-2:     #E0B44A;   /* lighter gold, for gradients */
  --accent-light: #F8EFD9;

  /* ---- Colours: status (contacts / follow-ups) ---- */
  --status-new:        #3B6EA5;
  --status-contacted:  #7C5FB0;
  --status-followup:   #C8992F;
  --status-converted:  #2E8F5F;
  --status-lost:       #9AA0AC;

  --status-overdue:    #C04A3F;
  --status-due-today:  #C8992F;
  --status-upcoming:   #3B6EA5;

  --success: #2E8F5F;
  --warning: #C8992F;
  --danger:  #C04A3F;
  --info:    #3B6EA5;

  /* ---- Spacing scale ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* ---- Radius ---- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 1px 3px rgba(15, 25, 45, 0.08), 0 1px 2px rgba(15, 25, 45, 0.05);
  --shadow-md: 0 6px 16px rgba(15, 25, 45, 0.10), 0 2px 6px rgba(15, 25, 45, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 25, 45, 0.18), 0 4px 12px rgba(15, 25, 45, 0.08);

  /* ---- Layout ---- */
  --max-content-width: 1120px;
  --nav-height: 56px;
  --tab-bar-height: 60px;   /* mobile bottom nav */
  --touch-target: 44px;     /* minimum tappable size on mobile */

  /* ---- Motion ---- */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur-normal: 200ms;
}

/* ---- Dark mode (optional, toggled later via class or prefers-color-scheme) ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #11151C;
    --bg-raised:   #1A202B;
    --bg-sunken:   #20262F;
    --border:      #2A313D;
    --border-soft: #242B35;

    --text:        #E7EAEE;
    --text-muted:  #A3ACBB;
    --text-faint:  #6B7485;

    --brand:        #2E5A8C;
    --brand-dark:   #0F2A4C;
    --brand-2:      #3E70A8;
    --brand-light:  #1B2838;
    --accent:       #D9AE4E;
    --accent-2:     #E8C06A;
    --accent-light: #3A2F1C;
  }
}

/* ==========================================================================
   Base element defaults — keep minimal, components override as needed.
   ========================================================================== */

body {
  font-family: var(--font-main);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
}

h1 { font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
h3 { font-size: var(--fs-md); font-weight: var(--fw-medium); line-height: var(--lh-tight); }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  color: var(--text-on-brand);
  border-radius: var(--radius-sm);
  font-weight: var(--fw-medium);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: var(--brand-dark);
  border-radius: var(--radius-sm);
  font-weight: var(--fw-bold);
}

.badge-overdue    { background: var(--status-overdue);   color: #fff; }
.badge-due-today  { background: var(--status-due-today); color: #fff; }
.badge-upcoming   { background: var(--status-upcoming);  color: #fff; }

/* ==========================================================================
   Shared app layout — top bar + mobile bottom tab bar, used on every
   logged-in page via app.js (renderTopBar / renderNav).
   ========================================================================== */

body.app {
  margin: 0;
  padding-top: var(--nav-height);
  padding-bottom: calc(var(--tab-bar-height) + var(--sp-4));
  min-height: 100vh;
  box-sizing: border-box;
}

.top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: linear-gradient(120deg, var(--brand-dark), var(--brand) 60%, var(--brand-2));
  color: var(--text-on-brand);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-4);
  z-index: 50;
  box-shadow: var(--shadow-md);
  border-bottom: 2px solid var(--accent);
}
.top-bar-title { font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: 0.2px; }
.top-bar-action { color: var(--text-on-brand); opacity: 0.85; font-size: var(--fs-sm); text-decoration: none; }

.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--tab-bar-height);
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--text-muted); font-size: var(--fs-xs);
  min-height: var(--touch-target);
}
.tab-item.active { color: var(--brand); font-weight: var(--fw-bold); }
.tab-icon { font-size: 20px; line-height: 1; }

.page-wrap { max-width: var(--max-content-width); margin: 0 auto; padding: var(--sp-4); }

.list-card {
  background: var(--bg-raised); border: 1px solid var(--border-soft); border-left: 3px solid var(--brand-2);
  border-radius: var(--radius-md);
  padding: var(--sp-4); margin-bottom: var(--sp-3); box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-normal) var(--ease), transform var(--dur-normal) var(--ease);
}
.list-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.list-card .row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); }
.list-card .name { font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--brand-dark); }
.list-card .meta { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.list-card .note { font-size: var(--fs-sm); color: var(--text); margin-top: var(--sp-2); }

.badge { display: inline-block; padding: 3px var(--sp-3); border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: 0.3px; }

.empty-state { text-align: center; color: var(--text-faint); padding: var(--sp-10) var(--sp-4); font-size: var(--fs-sm); }

.fab {
  position: fixed; bottom: calc(var(--tab-bar-height) + var(--sp-4)); right: var(--sp-4);
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: var(--fw-bold); text-decoration: none; box-shadow: var(--shadow-lg); z-index: 40;
  border: 2px solid var(--bg-raised);
}

.form-field { margin-bottom: var(--sp-4); }
.form-field label { display: block; font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-1); }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; box-sizing: border-box; padding: var(--sp-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-sunken); font-family: var(--font-main);
  font-size: var(--fs-base); color: var(--text); min-height: var(--touch-target);
}
.form-field textarea { min-height: 80px; }
.checkbox-field { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); margin-bottom: var(--sp-4); }

.submit-btn {
  width: 100%; padding: var(--sp-3); border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: var(--text-on-brand); font-size: var(--fs-base);
  font-weight: var(--fw-bold); min-height: var(--touch-target); cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-normal) var(--ease), transform var(--dur-normal) var(--ease);
}
.submit-btn:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.link-btn { background: none; border: none; color: var(--brand); font-size: var(--fs-sm); cursor: pointer; padding: 0; }

.hidden { display: none !important; }

.project-pick-row {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--sp-3); margin-bottom: var(--sp-2); background: var(--bg-sunken);
}
.project-pick-row label.check-label {
  display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-base); color: var(--text); cursor: pointer;
}
.project-pick-row select { margin-top: var(--sp-2); }

/* Modal — replaces native prompt()/confirm() dialogs everywhere. */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 40, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--bg-raised); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%; max-width: var(--max-content-width); padding: var(--sp-5);
  box-shadow: var(--shadow-lg); box-sizing: border-box;
  max-height: 85vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: var(--radius-lg); margin: var(--sp-4); }
}
.modal-box h3 { margin: 0 0 var(--sp-4) 0; }
.modal-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }
.modal-actions button { flex: 1; }
.btn-secondary {
  background: var(--bg-sunken); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-height: var(--touch-target); font-size: var(--fs-base); cursor: pointer;
}
