/* ══════════════════════════════════════════════════════════════════════════
   TECHOS Manage — Design System
   Phase 0: token-based rewrite. All legacy class names + their exact visual
   output are preserved (parity) so the app renders identically. New
   primitives (btn variants, alerts, cards, empty states, utilities) are
   additive and consumed by templates in later phases.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  /* Brand / navigation */
  --navy-900: #1a1a2e;   /* sidebar bg, table header */
  --navy-700: #2d2d5e;   /* sidebar hover/active bg */
  --navy-500: #3d3d6e;   /* sidebar borders */
  --blue-400: #74b9ff;   /* sidebar accent, info */
  --blue-600: #0984e3;   /* primary action */
  --blue-700: #0768b3;   /* primary hover */
  --blue-100: #eaf3fd;

  /* Semantic */
  --green-500: #00b894;
  --green-600: #00a381;
  --green-100: #e6faf4;
  --red-500: #e74c3c;
  --red-600: #d63031;
  --red-100: #fdecec;
  --amber-400: #fdcb6e;
  --amber-500: #f5b041;
  --amber-100: #ffeaa7;
  --purple-500: #6c5ce7;
  --purple-100: #f0edfe;

  /* Ink / neutrals */
  --ink-900: #2d3436;    /* primary text */
  --ink-600: #636e72;    /* muted text */
  --ink-400: #b2bec3;    /* faint text */
  --ink-200: #dfe6e9;    /* soft border */
  --ink-100: #eeeeee;    /* hairline */

  /* Surfaces */
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-hover: #f8f9ff;
  --border: #e6e8ee;
  --border-strong: #d0d4da;
  --field-border: #dddddd;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 22px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  /* Layout */
  --sidebar-w: 280px;

  /* Motion */
  --ease: .18s ease;
}

/* ── Reset & base ───────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink-900);
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0; width: var(--sidebar-w); height: 100%;
  background: var(--navy-900); color: white; padding: var(--sp-4); overflow-y: auto;
}
.sidebar h1 { font-size: var(--text-xl); margin-bottom: var(--sp-4); color: var(--blue-400); }

.main { margin-left: var(--sidebar-w); padding: var(--sp-4); }

/* Page header — title left, action(s) right, subtitle on its own row.
   .header is the legacy class used across the app; upgrading it here
   realigns every page's header with one change. .page-header is the
   semantic alias for new templates. */
.header, .page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.header > p, .page-header > p { flex-basis: 100%; margin: 0; color: var(--ink-600); }
.header h2, .page-header h2 { font-size: var(--text-2xl); color: var(--navy-900); margin: 0; }
.page-title { font-size: var(--text-2xl); font-weight: 700; color: var(--navy-900); margin: 0; }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
h3 { color: var(--navy-900); margin: 10px 0 3px; }
h4 { color: var(--ink-600); }

/* ── Page header w/ actions (Phase 1+) ─────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.page-title { font-size: var(--text-2xl); font-weight: 700; color: var(--navy-900); margin: 0; }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* ── Stat cards ─────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.stat-card {
  background: var(--surface); padding: var(--sp-4); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.stat-card .num { font-size: 32px; font-weight: 700; color: var(--navy-900); }
.stat-card .label { font-size: var(--text-sm); color: var(--ink-600); margin-top: var(--sp-1); }
.stat-card.critical .num { color: var(--red-600); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
table {
  width: 100%; background: var(--surface); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
th {
  background: var(--navy-900); color: white; padding: 12px 16px; text-align: left;
  font-size: var(--text-sm); text-transform: uppercase; letter-spacing: .5px;
}
td { padding: 12px 16px; border-bottom: 1px solid var(--ink-100); font-size: var(--text-base); }
tr:hover td { background: var(--surface-hover); }
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: var(--text-xs); font-weight: 600;
}
.badge-critical { background: var(--amber-100); color: var(--red-600); }
.badge-high     { background: #fab1a0;      color: #c0392b; }
.badge-medium   { background: var(--ink-200); color: var(--ink-600); }
.badge-low      { background: #55efc4;      color: var(--green-500); }
.badge-open     { background: var(--blue-400); color: var(--blue-600); }
.badge-progress { background: var(--amber-100); color: var(--red-600); }
.badge-waiting  { background: #fab1a0;      color: #c0392b; }
.badge-resolved { background: #55efc4;      color: var(--green-500); }
.badge-closed   { background: var(--ink-200); color: var(--ink-600); }
.badge-custom   { background: var(--purple-500); color: #fff; }
.badge-override { background: #ffeaa7; color: #d63031; }
.badge-default  { background: #dfe6e9; color: #636e72; }
.badge-draft    { background: #fdcb6e; color: #2d3436; }
.badge-auto     { background: #81ecec; color: #0984e3; }
.badge-running  { background: #ffeaa7; color: #6b5b00; }
.badge-error    { background: #ff7675; color: #fff; }
.badge-idle     { background: #55efc4; color: #0a3d2e; }
.badge-never    { background: #dfe6e9; color: #636e72; }
.badge-sev-critical { background: var(--red-600); color: #fff; }
.badge-sev-important { background: #e67e22; color: #fff; }
.badge-sev-moderate { background: #fdcb6e; color: #2d3436; }
.badge-sev-low { background: #55efc4; color: var(--green-500); }
.badge-success { background: var(--green-100); color: var(--green-600); }
.badge-info    { background: var(--blue-100); color: var(--blue-700); }
.badge-warning { background: var(--amber-100); color: #9a6a00; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block; padding: 8px 18px; border-radius: var(--radius-md);
  text-decoration: none; font-size: var(--text-base); font-weight: 600;
  border: none; cursor: pointer;
}
.btn-primary { background: var(--blue-600); color: white; }
.btn-primary:hover { background: var(--blue-700); }
.btn-success { background: var(--green-500); color: white; }
.btn-success:hover { background: var(--green-600); }
.btn-danger { background: var(--red-600); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--amber-400); color: var(--navy-900); }
.btn-warning:hover { background: var(--amber-500); }
.btn-purple { background: var(--purple-500); color: white; }
.btn-purple:hover { background: #5a4bd1; }
.btn-outline { background: transparent; color: var(--blue-600); border: 1px solid var(--blue-600); }
.btn-outline:hover { background: var(--blue-100); }
.btn-outline-danger { background: transparent; color: var(--red-600); border: 1px solid var(--red-600); }
.btn-outline-danger:hover { background: var(--red-100); }
.btn-ghost { background: var(--ink-100); color: var(--ink-600); }
.btn-ghost:hover { background: var(--ink-200); color: var(--ink-900); }
.btn-sm { padding: 5px 12px; font-size: var(--text-xs); }
.btn-lg { padding: 10px 24px; font-size: var(--text-lg); }
.btn-block { display: block; width: 100%; text-align: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
form {
  background: var(--surface); padding: var(--sp-4); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); max-width: 600px;
}
label { display: block; font-size: var(--text-base); font-weight: 600; margin-bottom: var(--sp-1); color: var(--ink-900); }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--field-border);
  border-radius: var(--radius-md); font-size: var(--text-base);
  margin-bottom: 10px; font-family: inherit;
}
textarea { min-height: 100px; resize: vertical; }
.form-card { background: var(--surface); padding: var(--sp-4); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.field-hint { font-size: var(--text-xs); color: var(--ink-600); margin: -6px 0 8px; }

/* ── Horizontal filter/search toolbar ─────────────────────────────────────
   Overrides the global `form` card + full-width inputs so filters sit in a
   single horizontal row. Reusable across pages. */
.filter-bar {
  background: none; padding: 0; border-radius: 0; box-shadow: none;
  max-width: none; display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center; margin-bottom: var(--sp-4);
}
.filter-bar input[type="text"],
.filter-bar select,
.filter-bar .btn,
.filter-bar button { width: auto; margin: 0; }
.filter-bar input[type="text"] { flex: 1; min-width: 200px; }
/* Compact select used inside page headers / toolbars (keeps auto width,
   neutral margin so it sits on the same baseline as adjacent buttons). */
.filter-select { width: auto; display: inline-block; margin: 0; }
/* Bounded search field used in toolbars (flexes up to a cap). */
.search-input { flex: 1; max-width: 300px; }
.toolbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }

/* ── Cards / panels ─────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-header { padding: var(--sp-4) var(--sp-4) 0; }
.card-title { font-size: var(--text-lg); font-weight: 700; color: var(--navy-900); margin: 0; }
.card-body { padding: var(--sp-4); }
/* Small uppercase section label used atop detail panels (e.g. Ticket Info,
   Update Ticket, Description). */
.section-label { margin: 0 0 var(--sp-3) 0; font-size: var(--text-sm); color: var(--ink-600); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
/* Compact uppercase label for form fields in tight grids. */
.field-label { font-size: 11px; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .5px; }
.ticket-detail {
  background: var(--surface); padding: var(--sp-4); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); margin-bottom: 10px;
}
.ticket-detail h2 { font-size: var(--text-2xl); margin-bottom: var(--sp-3); }
/* Row card for lists of records (trash items, activity, etc.) */
.list-card {
  background: var(--surface); border-radius: var(--radius-md); padding: var(--sp-4);
  box-shadow: var(--shadow-xs); display: flex; justify-content: space-between;
  align-items: center; gap: var(--sp-3); border: 1px solid var(--border);
}

/* ── Alerts (Phase 1+) ──────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px; border-radius: var(--radius-md); margin-bottom: var(--sp-4);
  font-size: var(--text-base); display: flex; align-items: flex-start; gap: var(--sp-2);
}
.alert-success { background: var(--green-100); color: var(--green-600); border: 1px solid #bfeadd; }
.alert-danger  { background: var(--red-100); color: var(--red-600); border: 1px solid #f6cccc; }
.alert-warning { background: var(--amber-100); color: #9a6a00; border: 1px solid #f6dfb8; }
.alert-info    { background: var(--blue-100); color: var(--blue-700); border: 1px solid #cfe3f7; }

/* ── Empty states ───────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: var(--sp-6); color: var(--ink-600); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: var(--sp-2); opacity: .5; }
.empty-state .empty-title { font-size: var(--text-lg); font-weight: 600; color: var(--ink-900); margin-bottom: var(--sp-1); }
.empty-state .empty-sub { font-size: var(--text-sm); color: var(--ink-600); }

/* ── Ticket detail pieces ───────────────────────────────────────────────── */
.meta { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.meta-item { font-size: var(--text-sm); color: var(--ink-600); }
.meta-item strong { color: var(--ink-900); }
.note { border-left: 3px solid var(--blue-400); padding: 8px 12px; margin: 3px 0; background: var(--surface-hover); border-radius: 0 8px 8px 0; }
.note.internal { border-left-color: var(--red-600); background: #fff5f5; }
.note .author { font-size: var(--text-xs); color: var(--ink-600); }
.time-entry { padding: 4px 0; border-bottom: 1px solid var(--ink-100); font-size: var(--text-base); }
.inline-form { display: inline; }
.inline-form form {
  display: inline; background: none; padding: 0; border-radius: 0;
  box-shadow: none; max-width: none; margin: 0;
}
.inline-form form button, .inline-form button { margin: 0; }
.row { display: flex; gap: 20px; align-items: start; }
.col { flex: 1; }
.hamburger { display: none; }

/* ── Utilities ──────────────────────────────────────────────────────────── */
.text-muted { color: var(--ink-600); }
.text-danger { color: var(--red-600); }
.text-success { color: var(--green-600); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flex { display: flex; align-items: center; gap: var(--sp-2); }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.mt-1 { margin-top: var(--sp-1); } .mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
.mb-1 { margin-bottom: var(--sp-1); } .mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); }
.m-0 { margin: 0; } .p-0 { padding: 0; }

/* ── Mobile Drawer Sidebar ── */
@media (max-width: 768px) {
  .sidebar {
    width: var(--sidebar-w); height: 100%; position: fixed;
    left: -280px; top: 0; z-index: 1000;
    transition: left .25s ease;
    padding: var(--sp-4); overflow-y: auto;
  }
  .sidebar.open { left: 0; }
  .main { margin-left: 0; padding-top: 48px; }
  .row { flex-direction: column; }

  /* Hamburger toggle — floating button, top-left */
  .hamburger {
    display: flex; position: fixed; top: 10px; left: 10px;
    z-index: 1001; background: none; border: none;
    color: var(--navy-900); font-size: 28px; cursor: pointer;
    padding: 4px; line-height: 1; width: 40px; height: 40px;
    align-items: center; justify-content: center;
    border-radius: var(--radius-md);
  }
  .hamburger:active { background: rgba(0,0,0,.08); }

  /* Overlay behind open drawer */
  .sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.45); z-index: 999;
  }
  .sidebar-overlay.show { display: block; }

  /* Tables scroll horizontally instead of squishing */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  td, th { white-space: nowrap; }

  /* Forms full width on mobile */
  form { max-width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ── Collapsible Sidebar Sections ── */
.sidebar-logo { text-align: center; margin-bottom: var(--sp-3); }
.sidebar-logo img { max-width: 180px; height: auto; margin-bottom: var(--sp-1); }
.sidebar-link {
  display: block; color: var(--ink-200); text-decoration: none;
  padding: 8px 12px; border-radius: var(--radius-sm);
  margin-bottom: 2px; font-size: var(--text-base);
  transition: background var(--ease), color var(--ease);
}
.sidebar-link:hover, .sidebar-link.active { background: var(--navy-700); color: var(--blue-400); }
.sidebar-section { margin-bottom: var(--sp-1); }
.section-dropdown {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--ink-200); font-size: var(--text-base); text-decoration: none;
  transition: background var(--ease), color var(--ease);
}
.section-dropdown:hover { background: var(--navy-700); color: var(--blue-400); }
.drop-arrow { font-size: 10px; transition: transform .2s; color: var(--ink-400); }
.sidebar-section.expanded .drop-arrow { transform: rotate(90deg); color: var(--blue-400); }
.section-links { display: none; }
.sidebar-section.expanded .section-links, .sidebar-section.expanded_nav .section-links { display: block; }
.section-links .sidebar-link { padding-left: 24px; font-size: var(--text-sm); }

/* ── Auth / login (Phase 3) ────────────────────────────────────────────── */
.auth-body {
  background: var(--navy-900);
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; padding: var(--sp-4); margin: 0;
}
.auth-card {
  background: var(--surface); width: 100%; max-width: 380px;
  padding: var(--sp-6); border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.auth-card .auth-logo {
  font-family: 'Inter', 'Roboto', sans-serif; font-weight: 800;
  font-size: 30px; letter-spacing: 1px; text-align: center; margin-bottom: 2px;
}
.auth-card .auth-sub { color: var(--ink-600); font-size: 14px; text-align: center; margin-bottom: var(--sp-5); }
.auth-card label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--navy-900); }
.auth-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--ink-200);
  border-radius: var(--radius-md); font-size: 14px; margin-bottom: var(--sp-4); background: var(--surface);
}
.auth-card input:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px var(--blue-100); }
.auth-card .btn { width: 100%; padding: 10px; font-size: 14px; }
.auth-error {
  background: var(--red-100); color: var(--red-600); border: 1px solid #f6cccc;
  padding: 10px 14px; border-radius: var(--radius-md); font-size: 13px;
  margin-bottom: var(--sp-4); text-align: center;
}

.sidebar-footer { margin-top: 24px; border-top: 1px solid var(--navy-700); padding-top: var(--sp-3); }
.sidebar-footer .user-name { font-size: var(--text-sm); color: var(--blue-400); }
.sidebar-footer .user-role { font-size: 11px; color: var(--ink-600); margin-bottom: var(--sp-2); }
.logout-link { font-size: var(--text-xs); color: var(--red-600); text-decoration: none; display: inline-block; }
.logout-link:hover { color: var(--red-600); }

/* ── Phase 3 polish: focus, touch, stat refinement ─────────────────────── */
/* Visible focus rings for keyboard nav — never rely on outline:none alone */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--blue-600);
  outline-offset: 2px;
}
.btn:focus-visible, .sidebar-link:focus-visible, .logout-link:focus-visible {
  outline-color: var(--blue-400);
}
/* Keyboard nav only (no focus ring on mouse click) */
a:focus:not(:focus-visible), button:focus:not(:focus-visible) { outline: none; }

/* Refined stat cards — hairline border + tighter rhythm */
.stat-card {
  border: 1px solid var(--ink-200);
  transition: transform var(--ease), box-shadow var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-card .num { font-variant-numeric: tabular-nums; }

/* Mobile touch targets — generous tap sizes for primary controls only,
   so compact table/form buttons (.btn-sm etc.) aren't bloated */
@media (max-width: 768px) {
  .page-actions .btn, .btn-primary, .btn-success, .btn-danger, .btn-warning, .btn-purple,
  .toolbar .btn-primary, .sidebar-link { min-height: 44px; }
  input, select, textarea { font-size: 16px; }  /* prevents iOS zoom-on-focus */
  .page-actions { gap: var(--sp-2); }
  .header > p, .page-header > p { font-size: var(--text-sm); }
  .hamburger { width: 44px; height: 44px; }
  .stat-card .num { font-size: 28px; }
}


