/* =========================================================================
   CPWD Portal — Base styles: brand tokens, reset, shared shell
   (sidebar / header / footer), shared table & form primitives
   ========================================================================= */

:root {
  /* ---- CPWD brand palette (source of truth for shipped defaults) ----- */
  --cpwd-charcoal: #333333;     /* Heading / primary text */
  --cpwd-blue: #0056B3;         /* Primary brand */
  --cpwd-navy: #0D2C54;         /* Primary dark / navigation */
  --cpwd-green: #2E7D32;        /* Secondary brand */
  --cpwd-teal: #00A5A8;         /* Teal accent */
  --cpwd-gold: #FFC107;         /* Highlight / accent gold (decorative use only — see note below) */
  --cpwd-sky-blue: #E6F2FF;     /* Info / light accent */
  --cpwd-mint-green: #E8F5E9;   /* Success background */
  --cpwd-off-white: #F7F9FC;    /* Page background */
  --cpwd-white: #FFFFFF;        /* Card background */
  --cpwd-border: #D9DEE3;       /* Border */
  --cpwd-dark-gray: #60707B;    /* Secondary text */

  /* =====================================================================
     CUSTOMIZABLE DESIGN TOKENS ("--t-*")
     This is the single source of truth for the "Appearance → Customize
     Theme" panel. Every field in that panel edits exactly one of these
     variables. Every other rule in every stylesheet in this project reads
     colors *through* these tokens (directly or via a legacy alias below),
     so changing one token here updates every matching component at once.
     ===================================================================== */
  --t-bg: var(--cpwd-off-white);          /* Background Color */
  --t-primary: var(--cpwd-blue);          /* Primary Color */
  --t-secondary: var(--cpwd-green);       /* Secondary Color */
  --t-accent: var(--cpwd-teal);           /* Accent Color */
  --t-text: var(--cpwd-charcoal);         /* Text Color */
  --t-card: var(--cpwd-white);            /* Card Color */
  --t-sidebar: var(--cpwd-navy);          /* Sidebar Color */
  --t-header: var(--cpwd-navy);           /* Header Color */
  --t-border: var(--cpwd-border);         /* Border Color */
  --t-success: var(--cpwd-green);         /* Success Color */
  --t-warning: #8A5A00;                   /* Warning Color (AA-legible amber) */
  --t-error: #D93025;                     /* Error Color */
  --t-btn-bg: var(--t-primary);           /* Button Background Color */
  --t-btn-text: #FFFFFF;                  /* Button Text Color */
  --t-btn-hover: #00406E;                 /* Button Hover / Active Color */
  --t-input-bg: var(--cpwd-white);        /* Input Background Color */
  --t-input-border: #BFD0E4;              /* Input Border Color */
  --t-table-header-bg: var(--cpwd-navy);  /* Table Header Background */
  --t-table-row-alt: #F7FAFD;             /* Table Row Stripe */
  --t-badge-bg: var(--cpwd-sky-blue);     /* Badge Background */
  --t-badge-text: var(--t-primary);       /* Badge Text */
  --t-icon: var(--t-primary);             /* Icon Color */

  /* ---- Legacy/internal aliases -----------------------------------------
   * Every component stylesheet was written against these shorter names.
   * They now simply forward to the canonical --t-* tokens above, so no
   * component CSS had to change: customizing a --t-* token upstream
   * updates every rule below automatically.
   * `--heading`  heading/strong text on cards — not one of the 22
   *              customizable fields, stays a fixed brand-navy tone.
   * ---------------------------------------------------------------------*/
  --navy: var(--t-sidebar);
  --navy-2: var(--t-table-header-bg);
  --heading: var(--cpwd-navy);
  --blue: var(--t-primary);
  --blue-soft: var(--t-badge-bg);
  --on-accent: var(--t-btn-text);
  --text: var(--t-text);
  --muted: var(--cpwd-dark-gray);
  --bg: var(--t-bg);
  --white: var(--t-card);
  --border: var(--t-border);
  --green: var(--t-success);
  --green-soft: var(--cpwd-mint-green);
  --lime: #78b822;
  --amber: var(--t-warning);
  --gold-highlight: var(--cpwd-gold); /* pure spec gold, decorative/background use only */
  --orange: #ef7900;
  --red: var(--t-error);
  --purple: #8756c7;
  --teal: var(--t-accent);
  --row-alt: var(--t-table-row-alt);
  --input-border: var(--t-input-border);

  /* ---- Recurring surface tints not exposed as standalone fields ------- */
  --row-total: #edf3f9;        /* emphasised total/summary rows */
  --control-bg: #edf4fb;       /* segmented control / filter-button rest state */
  --surface-tint: #fbfdff;     /* faint panel/input backgrounds */
  --surface-tint-2: #f8fafc;   /* modal body / search panel backgrounds */
  --chip-neutral-bg: #eef3f8;  /* neutral status chip background */
  --table-border-strong: #123255; /* table header cell divider on navy */

  --sidebar-width: 250px;
  --collapsed-sidebar-width: 72px;
  --header-height: 64px;
  --shadow: 0 4px 18px rgba(13, 44, 84, .08);
}

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

/* The native `hidden` attribute must always win over component display
   rules (flex/grid) that would otherwise override it on specificity ties. */
[hidden] { display: none !important; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; }
h1, h2, h3, p { margin: 0; }

.app-shell { min-height: 100vh; }

/* ---------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--navy);
  color: #fff;
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .22s cubic-bezier(.4, 0, .2, 1);
}

body.sidebar-collapsed .sidebar { width: var(--collapsed-sidebar-width); }

.brand-block {
  height: var(--header-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 0 18px;
}

body.sidebar-collapsed .brand-block { justify-content: center; padding: 0; }

.menu-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 25px;
  line-height: 1;
}

.side-nav {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .35) transparent;
}

.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-track { background: transparent; }
.side-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .35); border-radius: 999px; }

.nav-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #eff5fc;
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: background-color .16s ease, padding .22s ease;
}

.nav-item:hover, .nav-item.active { background: var(--blue); color: var(--on-accent); }
.nav-item span { display: block; width: 100%; white-space: normal; }

.nav-item.nav-button { cursor: not-allowed; opacity: .62; }
.nav-item.nav-button:hover { background: transparent; }

body.sidebar-collapsed .side-nav { padding-inline: 8px; }

body.sidebar-collapsed .nav-item {
  min-height: 8px;
  height: 8px;
  margin: 4px 13px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .25);
  pointer-events: none;
}

body.sidebar-collapsed .nav-item.active { background: var(--blue); }
body.sidebar-collapsed .nav-item span { display: none; }

@media (max-width: 768px) {
  .sidebar { width: min(280px, 85vw); box-shadow: 0 0 18px rgba(0, 0, 0, .28); }
  body.sidebar-collapsed .sidebar { width: 0; box-shadow: none; }
}

.sidebar-scrim {
  position: fixed; inset: 0; z-index: 29; background: rgba(13, 44, 84, .45);
}
@media (min-width: 769px) { .sidebar-scrim { display: none !important; } }

/* ---------------------------------------------------------------------
   Header
   --------------------------------------------------------------------- */
.shared-header {
  position: fixed;
  top: 0;
  right: 0;
  left: var(--sidebar-width);
  z-index: 25;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: var(--t-header);
  color: #fff;
  transition: left .22s cubic-bezier(.4, 0, .2, 1);
}

body.sidebar-collapsed .shared-header { left: var(--collapsed-sidebar-width); }

.header-left { min-width: 0; display: flex; align-items: center; gap: 12px; }

.logo-container {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--white);
  overflow: hidden;
}
.logo-container img { width: 100%; height: 100%; object-fit: cover; }

.dashboard-header-title { min-width: 0; display: flex; align-items: center; }
.dashboard-title { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; color: #fff; }
.dashboard-title span { font-size: 18px; font-weight: 800; white-space: nowrap; }
.brand-subtitle { color: rgba(255, 255, 255, .76); font-size: 11px; }

.mobile-menu-button { display: none; width: 36px; height: 36px; border: 0; background: transparent; color: #fff; cursor: pointer; font-size: 24px; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.profile-menu { position: relative; }
.profile-badge {
  width: 42px; height: 42px; border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 50%; background: rgba(255, 255, 255, .08); color: #fff;
  font-weight: 800; cursor: pointer;
}
.profile-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 140px;
  padding: 6px 0; border: 1px solid var(--border); border-radius: 8px;
  background: var(--white); box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .16s ease, visibility .16s ease, transform .16s ease;
}
.profile-menu:hover .profile-dropdown, .profile-menu:focus-within .profile-dropdown {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.profile-menu.open .profile-dropdown {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.dropdown-item { display: block; padding: 10px 16px; color: var(--text); font-size: 12px; text-decoration: none; }
.dropdown-item:hover { background: var(--blue-soft); color: var(--blue); }
.dropdown-item-button {
  width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

/* ---------------------------------------------------------------------
   Customize Theme panel (Profile menu → Customize Theme)
   --------------------------------------------------------------------- */
.appearance-backdrop {
  position: fixed; inset: 0; z-index: 1100; background: rgba(13, 44, 84, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.appearance-modal {
  width: min(560px, 100%); max-height: 92vh; background: var(--white); border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0,0,0,.35); display: flex; flex-direction: column; overflow: hidden;
}
.appearance-modal > header {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.appearance-modal > header small { color: var(--blue); font-weight: 800; letter-spacing: .06em; font-size: 10px; }
.appearance-modal > header h2 { margin: 2px 0 0; color: var(--heading); font-size: 19px; }
.appearance-modal > header button {
  width: 36px; height: 36px; border: 0; border-radius: 50%; font-size: 22px; cursor: pointer;
  background: var(--control-bg); color: var(--heading);
}
.appearance-body { flex: 1 1 auto; overflow-y: auto; padding: 20px 22px; }
.appearance-hint { margin: 0 0 12px; color: var(--muted); font-size: 11px; }

.appearance-modal > footer {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}
.appearance-footer-group { display: flex; gap: 10px; }

/* ---- Customize Theme: color field grid --------------------------------- */
.customize-group + .customize-group { margin-top: 22px; }
.customize-group h3 { margin: 0 0 10px; font-size: 12px; font-weight: 800; color: var(--heading); text-transform: uppercase; letter-spacing: .04em; }
.color-field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.color-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.color-field-label { font-size: 12px; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-field-controls { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.color-field-swatch {
  width: 32px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; background: none;
}
.color-field-swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.color-field-swatch::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color-field-swatch::-moz-color-swatch { border: 0; border-radius: 6px; }
.color-field-hex {
  width: 82px; height: 32px; border: 1px solid var(--border); border-radius: 7px;
  padding: 0 8px; font-size: 11px; font-family: "SFMono-Regular", Consolas, monospace;
  text-transform: lowercase; background: var(--white); color: var(--text);
}

@media (max-width: 560px) {
  .color-field-grid { grid-template-columns: 1fr; }
  .appearance-modal > footer { flex-direction: column-reverse; align-items: stretch; }
  .appearance-modal > footer button { width: 100%; }
  .appearance-footer-group { flex-direction: column; }
}

@media (max-width: 768px) {
  .shared-header, body.sidebar-collapsed .shared-header { left: 0; padding-inline: 12px; }
  .mobile-menu-button { display: grid; place-items: center; }
  .dashboard-title span { font-size: 15px; }
  .logo-container { width: 38px; height: 38px; flex-basis: 38px; }
}

/* ---------------------------------------------------------------------
   Main content shell
   --------------------------------------------------------------------- */
.main-content {
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left .22s cubic-bezier(.4, 0, .2, 1);
}
body.sidebar-collapsed .main-content { margin-left: var(--collapsed-sidebar-width); }
@media (max-width: 768px) { .main-content, body.sidebar-collapsed .main-content { margin-left: 0; } }

/* ---------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------- */
.shared-footer {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 12px 2px 4px; color: var(--muted); font-size: 9px;
}
@media (max-width: 600px) { .shared-footer { flex-direction: column; } }

/* ---------------------------------------------------------------------
   Generic building blocks reused by every page
   --------------------------------------------------------------------- */
.card { background: var(--white); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 1px 2px rgba(0,59,115,.05); }
.button { height: 36px; border-radius: 6px; padding: 0 17px; font-weight: 700; border: 1px solid var(--border); cursor: pointer; white-space: nowrap; background: var(--white); }
.button.primary { background: var(--t-btn-bg); color: var(--t-btn-text); border-color: var(--t-btn-bg); }
.button.secondary { background: var(--control-bg); color: var(--t-secondary); border-color: var(--t-secondary); }
.button.primary:hover, .button.primary:active,
.button.primary:focus-visible { background: var(--t-btn-hover); border-color: var(--t-btn-hover); }

.breadcrumb { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.breadcrumb a { color: var(--blue); font-weight: 700; }

.eyebrow { margin: 0 0 5px; color: var(--t-accent); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 800; }

/* Skip link for keyboard users */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200; background: var(--blue); color: var(--on-accent);
  padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
