/* KFC Case Management — UI 2.0 (spec §8). Single hand-authored stylesheet,
   driven by CSS custom properties. No build step. */

:root {
  --app-sidebar-width: 260px;
  --app-bg:          #F4F7FE;
  --app-surface:     #FFFFFF;
  --app-text:        #1B2559;
  --app-text-muted:  #707EAE;
  --app-border:      #E9EDF7;
  --app-accent:      #01303f;
  --app-accent-soft: #e8f1f4;
  --app-red:         #E4002B;
  --app-red-dark:    #c00020;
  --app-radius:      16px;
  --app-radius-sm:   10px;
  --app-shadow:      0 4px 24px rgba(112, 144, 176, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--app-bg);
  color: var(--app-text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--app-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Shell ---------- */
body.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 76px;
  background: var(--app-surface);
  border-right: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .18s ease;
  flex-shrink: 0;
}
body.sidebar-expanded .app-sidebar { width: var(--app-sidebar-width); }

.app-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 16px; border-bottom: 1px solid var(--app-border);
  min-height: 70px; justify-content: center;
}
body.sidebar-expanded .app-brand { justify-content: flex-start; gap: 12px; }
.app-brand-logo {
  height: 40px; width: 40px; object-fit: contain;
  display: block; flex-shrink: 0;
}
body.sidebar-expanded .app-brand-logo { height: 44px; width: 44px; }
.app-brand-text { font-weight: 700; white-space: nowrap; display: none; line-height: 1.2; }
body.sidebar-expanded .app-brand-text { display: block; }

.app-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.app-nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--app-text-muted); padding: 14px 12px 6px; display: none;
}
body.sidebar-expanded .app-nav-section { display: block; }

.app-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--app-radius-sm);
  color: var(--app-text-muted); font-weight: 600;
  margin-bottom: 4px; position: relative;
}
.app-nav-item:hover { background: var(--app-accent-soft); text-decoration: none; }
.app-nav-item.active { background: var(--app-accent-soft); color: var(--app-accent); }
.app-nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--app-accent);
}
.app-nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.app-nav-item span { white-space: nowrap; display: none; }
body.sidebar-expanded .app-nav-item span { display: inline; }

.app-sidebar-footer { border-top: 1px solid var(--app-border); padding: 12px; }
.app-user-card { display: flex; align-items: center; gap: 10px; }
.app-user-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--app-accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.app-user-info { min-width: 0; display: none; }
body.sidebar-expanded .app-user-info { display: block; }
.app-user-info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-user-info .role { font-size: 12px; color: var(--app-text-muted); }

/* ---------- Main ---------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  background: var(--app-surface); border-bottom: 1px solid var(--app-border);
  padding: 16px 28px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.app-topbar-toggle {
  background: none; border: none; cursor: pointer; color: var(--app-text-muted);
  padding: 6px; border-radius: 8px;
}
.app-topbar-toggle:hover { background: var(--app-accent-soft); }
.app-topbar h1 { font-size: 20px; margin: 0; }
.app-breadcrumb { color: var(--app-text-muted); font-size: 13px; }
.app-topbar-right { margin-left: auto; }

.container { padding: 28px; max-width: 1400px; width: 100%; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--app-surface); border-radius: var(--app-radius);
  box-shadow: var(--app-shadow); padding: 22px; margin-bottom: 22px;
}
.card h2 { margin-top: 0; font-size: 17px; }

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; margin-bottom: 22px;
}
.stat-card {
  background: var(--app-surface); border-radius: var(--app-radius);
  box-shadow: var(--app-shadow); padding: 18px 20px;
}
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--app-text-muted); font-size: 13px; }

table.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  text-align: left; font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; color: var(--app-text-muted);
  padding: 12px 14px; border-bottom: 1px solid var(--app-border);
}
.data-table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--app-border); }
.data-table tbody tr:hover td { background: var(--app-bg); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status-badge[data-s="Open"] { background: #e0f2fe; color: #0369a1; }
.status-badge[data-s="In Progress"] { background: #fef3c7; color: #92400e; }
.status-badge[data-s="Resolved"] { background: #dcfce7; color: #15803d; }
.status-badge[data-s="Closed"] { background: #e5e7eb; color: #374151; }
/* badges used outside the case table (admin active/inactive) */
.status-badge.Resolved { background: #dcfce7; color: #15803d; }
.status-badge.Closed { background: #e5e7eb; color: #374151; }

.priority-badge.High { background: #fee2e2; color: #b91c1c; }
.priority-badge.Medium { background: #fef3c7; color: #92400e; }
.priority-badge.Low { background: #e0e7ff; color: #3730a3; }

.type-badge.type-food_safety { background: #fee2e2; color: #b91c1c; }
.type-badge.type-order { background: #dbeafe; color: #1d4ed8; }
.type-badge.type-service { background: #ede9fe; color: #6d28d9; }

/* ---------- Status progress bar (per case) ---------- */
.status-progress {
  height: 6px; background: var(--app-border); border-radius: 4px;
  overflow: hidden; width: 100%; min-width: 80px; margin-top: 7px;
}
.status-progress-fill { height: 100%; border-radius: 4px; transition: width .3s ease; }
.status-progress-fill[data-s="Open"] { background: #0369a1; }
.status-progress-fill[data-s="In Progress"] { background: #d97706; }
.status-progress-fill[data-s="Resolved"] { background: #15803d; }
.status-progress-fill[data-s="Closed"] { background: #6b7280; }

/* ---------- Status step tracker (detail page) ---------- */
.status-steps { display: flex; align-items: flex-start; margin: 32px 0 28px; }
.status-step { flex: 1; text-align: center; position: relative; font-size: 12.5px; color: var(--app-text-muted); }
.status-step .dot {
  width: 28px; height: 28px; border-radius: 50%; margin: 0 auto 8px;
  background: var(--app-surface); border: 2px solid var(--app-border);
  color: var(--app-text-muted); display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700; position: relative; z-index: 2;
  transition: background .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.status-step .dot svg { width: 13px; height: 13px; display: block; }
.status-step::before {
  content: ''; position: absolute; top: 13px; left: calc(-50% + 22px);
  width: calc(100% - 44px); height: 2px; border-radius: 2px;
  background: var(--app-border); z-index: 1;
}
.status-step:first-child::before { display: none; }
.status-step.done .dot { background: var(--app-accent); border-color: var(--app-accent); color: #fff; }
.status-step.done::before, .status-step.active::before { background: var(--app-accent); }
.status-step.active .dot {
  border-color: var(--app-accent); color: var(--app-accent);
  box-shadow: 0 0 0 4px var(--app-accent-soft);
}
.status-step.active.complete .dot { background: var(--app-accent); color: #fff; }
.status-step.active { color: var(--app-text); font-weight: 600; }
.status-step .step-label { letter-spacing: .01em; }

/* ---------- SLA cell ---------- */
.sla-cell { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.sla-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.sla-ok .sla-dot { background: #22c55e; }
.sla-at_risk { color: #b45309; } .sla-at_risk .sla-dot { background: #f59e0b; }
.sla-breached { color: #b91c1c; } .sla-breached .sla-dot { background: #ef4444; animation: pulse 1.2s infinite; }
.sla-done { color: var(--app-text-muted); } .sla-done .sla-dot { background: #9ca3af; }
.sla-none { color: var(--app-text-muted); font-style: italic; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Breach banner ---------- */
.sla-breach-banner {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  border-radius: var(--app-radius); padding: 16px 20px; margin-bottom: 22px;
  display: flex; align-items: center; gap: 16px;
}
.sla-breach-banner strong { font-size: 15px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--app-border); background: var(--app-surface);
  color: var(--app-text); padding: 9px 16px; border-radius: var(--app-radius-sm);
  font-weight: 600; font-size: 14px; font-family: inherit;
}
.btn:hover { background: var(--app-bg); text-decoration: none; }
.btn-primary { background: var(--app-red); color: #fff; border-color: var(--app-red); }
.btn-primary:hover { background: var(--app-red-dark); border-color: var(--app-red-dark); }
.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm); font-family: inherit; font-size: 14.5px;
  background: #fff; color: var(--app-text); min-height: 44px;
}
.form-row select { min-width: 0; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--app-accent);
  box-shadow: 0 0 0 3px var(--app-accent-soft);
}
.form-row textarea { min-height: 100px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .form-row { margin-bottom: 0; }
.filters select, .filters input { min-width: 130px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27,37,89,.45);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 100; padding: 40px 16px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--app-surface); border-radius: var(--app-radius);
  width: 100%; max-width: 680px; padding: 28px; box-shadow: var(--app-shadow);
  max-height: 92vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Overlay (SLA) ---------- */
.sla-overlay { position: fixed; inset: 0; background: rgba(27,37,89,.45); display: none; z-index: 120; padding: 40px 16px; overflow-y: auto; }
.sla-overlay.open { display: block; }
.sla-overlay-panel { background: #fff; border-radius: var(--app-radius); max-width: 720px; margin: 0 auto; padding: 24px; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--app-text-muted); }
.empty-state h3 { color: var(--app-text); }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--app-text); color: #fff; padding: 12px 18px;
  border-radius: var(--app-radius-sm); box-shadow: var(--app-shadow);
  font-weight: 500; opacity: 0; transform: translateY(8px); transition: all .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 16px; justify-content: flex-end; color: var(--app-text-muted); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--app-bg); }
.login-card { background: #fff; border-radius: var(--app-radius); box-shadow: var(--app-shadow); padding: 38px; width: 100%; max-width: 400px; }
.login-card .brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 28px; text-align: center; }
.login-card .brand strong { font-size: 18px; }
.login-logo { height: 88px; width: 88px; object-fit: contain; display: block; }
.login-powered { text-align: center; margin: 20px 0 0; font-size: 12px; color: var(--app-text-muted); }
.login-powered a { color: var(--app-text-muted); font-weight: 600; }
.login-powered a:hover { color: var(--app-accent); }
.login-error { background: #fef2f2; color: #991b1b; padding: 10px 14px; border-radius: var(--app-radius-sm); margin-bottom: 14px; font-size: 13px; }

/* ---------- Dashboard ---------- */
.dash-welcome { margin-bottom: 22px; }
.dash-welcome h1 { margin: 0 0 4px; font-size: 24px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.dash-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dash-card-head h2 { margin: 0; }
.dash-list { display: flex; flex-direction: column; }
.dash-item {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 14px 6px; border-bottom: 1px solid var(--app-border); color: inherit;
}
.dash-item:last-child { border-bottom: none; }
.dash-item:hover { background: var(--app-bg); text-decoration: none; border-radius: var(--app-radius-sm); }
.dash-item-main { min-width: 0; }
.dash-item-title { font-weight: 700; }
.dash-item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; white-space: nowrap; flex-shrink: 0; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* ---------- Activity feed (per case) ---------- */
.feed-form { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--app-border); }
.feed-compose { display: flex; gap: 12px; align-items: flex-start; }
.composer {
  flex: 1; border: 1px solid var(--app-border); border-radius: var(--app-radius-sm);
  background: #fff; overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--app-accent); box-shadow: 0 0 0 3px var(--app-accent-soft); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none; display: block;
  min-height: 64px; padding: 12px 14px; font-family: inherit; font-size: 14.5px;
  color: var(--app-text); background: transparent;
}
.composer textarea::placeholder { color: var(--app-text-muted); }
.composer-actions {
  display: flex; justify-content: flex-end; padding: 8px 10px;
  border-top: 1px solid var(--app-border); background: var(--app-bg);
}
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--app-border); }
.feed-item:last-child { border-bottom: none; }
.feed-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; font-size: 13px;
  background: var(--app-accent); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.feed-body { min-width: 0; flex: 1; }
.feed-system { align-items: center; padding: 10px 0; }
.feed-system .feed-meta { margin-bottom: 0; font-size: 12.5px; }
.feed-avatar-system { background: var(--app-accent-soft); color: var(--app-accent); }
.feed-avatar-system svg { width: 16px; height: 16px; }
.feed-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--app-text-muted); margin-bottom: 4px; }
.feed-meta-text { min-width: 0; }
.feed-meta strong { color: var(--app-text); }
.feed-text { white-space: pre-wrap; word-wrap: break-word; }
.feed-meta em { font-style: italic; }
.feed-edit-btn {
  margin-left: auto; flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 1px solid transparent; cursor: pointer;
  color: var(--app-text-muted); font-weight: 600; font-size: 12px; font-family: inherit;
  padding: 5px 11px; border-radius: 999px; transition: color .15s, background .15s;
}
.feed-edit-btn svg { width: 13px; height: 13px; }
.feed-edit-btn:hover { color: var(--app-accent); background: var(--app-accent-soft); text-decoration: none; }
.feed-edit-form { margin-top: 10px; }

.muted { color: var(--app-text-muted); }
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.images-grid figure { margin: 0; }
.images-grid img { width: 100%; height: 120px; object-fit: cover; border-radius: var(--app-radius-sm); border: 1px solid var(--app-border); }
.chart-box { position: relative; height: 280px; }

@media (max-width: 1024px) {
  body.sidebar-expanded .app-sidebar { width: 76px; }
  body.sidebar-expanded .app-brand-text,
  body.sidebar-expanded .app-nav-section,
  body.sidebar-expanded .app-nav-item span,
  body.sidebar-expanded .app-user-info { display: none; }
}
