/* ═══════════════════════════════════════════════════════════
   Warranty Management System — Global Design System
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:           #f4f5f0;
  --surface:      #ffffff;
  --surface-2:    #f9faf7;
  --border:       #e2e5dc;
  --border-focus: #0e7c66;
  --ink:          #1b201c;
  --ink-2:        #4a5449;
  --ink-3:        #8a9489;
  --accent:       #0e7c66;
  --accent-hover: #0a6354;
  --accent-soft:  #e0f2ec;
  --warn:         #b45309;
  --warn-soft:    #fef3c7;
  --danger:       #b91c1c;
  --danger-soft:  #fee2e2;
  --info:         #1d4ed8;
  --info-soft:    #dbeafe;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow:       0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:    0 12px 40px rgba(0,0,0,.12);
  --radius:       10px;
  --radius-lg:    16px;
  --sidebar-w:    220px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: .95rem; }

/* ── Layout shell ── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #e8ede9;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.1rem 1.1rem .8rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo {
  font-size: 1rem;
  font-weight: 800;
  color: #7de8cf;
  letter-spacing: .02em;
}
.sidebar-brand .sub {
  font-size: .72rem;
  color: #8a9489;
  margin-top: 2px;
}

.sidebar nav { flex: 1; padding: .5rem 0; }
.nav-group-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #5a6a5b;
  padding: .8rem 1rem .3rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .5rem 1rem;
  color: #c8d4c9;
  font-size: .88rem;
  font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .icon { font-size: 1rem; width: 1.2rem; text-align: center; flex-shrink: 0; }

/* ── Main content area ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 700; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

.page { padding: 1.5rem; flex: 1; }

/* ── Cards / Panels ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.card-header h2 { font-size: .95rem; font-weight: 700; }
.card-body { padding: 1.25rem; }

/* ── Metric cards ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.metric .m-label { font-size: .78rem; color: var(--ink-2); margin-bottom: .3rem; }
.metric .m-value { font-size: 1.6rem; font-weight: 800; color: var(--ink); line-height: 1; }
.metric .m-sub { font-size: .75rem; color: var(--ink-3); margin-top: .3rem; }
.metric.accent { background: var(--accent); border-color: var(--accent); }
.metric.accent .m-label,
.metric.accent .m-value,
.metric.accent .m-sub { color: #fff; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .48rem 1rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all .15s;
  line-height: 1.4;
  white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger    { background: var(--danger-soft); color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost     { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm        { padding: .3rem .7rem; font-size: .8rem; }
.btn-icon      { padding: .4rem .5rem; }

/* ── Forms ── */
.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
label.form-label { font-size: .8rem; font-weight: 600; color: var(--ink-2); }
.form-control {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.search-wrap { position: relative; }
.search-wrap input { padding-left: 2.2rem; }
.search-wrap .search-icon {
  position: absolute;
  left: .7rem; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.autocomplete-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  max-height: 240px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: .55rem .8rem;
  cursor: pointer;
  font-size: .88rem;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--accent-soft); }
.autocomplete-item .sub { font-size: .75rem; color: var(--ink-3); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
thead th {
  background: var(--surface-2);
  font-size: .75rem;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
tbody td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.td-muted { color: var(--ink-3); font-size: .8rem; }

/* ── Badges / Pills ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .18rem .55rem;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-blue   { background: var(--info-soft); color: var(--info); }
.badge-yellow { background: var(--warn-soft); color: var(--warn); }
.badge-red    { background: var(--danger-soft); color: var(--danger); }
.badge-gray   { background: #f1f5f1; color: var(--ink-2); }
.badge-teal   { background: var(--accent-soft); color: var(--accent); }

/* ── State colors ── */
.state-A1,.state-A2,.state-A3 { background:#fef3c7;color:#92400e; }
.state-B1,.state-B2 { background:#dbeafe;color:#1e40af; }
.state-C1,.state-C3 { background:#fee2e2;color:#991b1b; }
.state-C2,.state-C4,.state-C5 { background:#fde68a;color:#78350f; }
.state-C6 { background:#d1fae5;color:#065f46; }

/* ── Page filter bar ── */
.filter-bar {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: flex-end;
}
.filter-bar .form-control { min-width: 160px; }

/* ── Item list inside ticket ── */
.item-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: .6rem;
  background: var(--surface-2);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .6rem 1rem;
  align-items: start;
}
.item-row .item-num {
  width: 28px; height: 28px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 800;
  flex-shrink: 0; margin-top: 2px;
}

/* ── Workflow timeline ── */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
  content: '';
  position: absolute; left: .6rem; top: .4rem; bottom: .4rem;
  width: 2px; background: var(--border);
}
.tl-event { position: relative; margin-bottom: .9rem; }
.tl-dot {
  position: absolute;
  left: -1.5rem;
  top: .3rem;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.tl-body { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .8rem; }
.tl-meta { font-size: .74rem; color: var(--ink-3); margin-bottom: .2rem; }
.tl-content { font-size: .87rem; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(600px, 96vw);
  max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: .5rem;
}

/* ── Toast ── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 9999;
  display: flex; flex-direction: column; gap: .4rem;
}
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: .65rem 1rem;
  font-size: .85rem;
  min-width: 220px;
  box-shadow: var(--shadow);
  animation: slideup .2s ease;
}
.toast.success { background: var(--accent); }
.toast.error   { background: var(--danger); }
.toast.info    { background: #1d6fa4; white-space: pre-wrap; max-width: 340px; }
@keyframes slideup { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ── Misc helpers ── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-sm { font-size: .82rem; }
.text-muted { color: var(--ink-3); }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--ink-3);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: .5rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.loading { text-align: center; padding: 2rem; color: var(--ink-3); }
