:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #f7f8f9;
  --text: #1a2226;
  --muted: #667077;
  --border: #dfe3e6;
  --primary: #0d5f5c;
  --primary-dark: #094a47;
  --primary-light: #e6efee;
  --success: #15803d;
  --success-bg: #e5f3e8;
  --warning: #92400e;
  --warning-bg: #fbead0;
  --danger: #b3261e;
  --danger-bg: #faeaea;
  --info: #1d4ed8;
  --info-bg: #e6edfb;
  --slate-bg: #e7e9eb;
  --slate: #3b4348;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(20, 30, 30, 0.05), 0 1px 1px rgba(20, 30, 30, 0.04);
  --shadow-md: 0 2px 8px rgba(20, 30, 30, 0.08);
  --shadow-lg: 0 12px 28px rgba(20, 30, 30, 0.14);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
}

[data-theme="dark"] {
  --bg: #12191b;
  --surface: #182123;
  --surface-2: #1e282a;
  --text: #e3e9ea;
  --muted: #93a1a4;
  --border: #2b3538;
  --primary: #2f9490;
  --primary-dark: #227672;
  --primary-light: #1b2b2a;
  --success-bg: #143323;
  --warning-bg: #33260f;
  --danger-bg: #351816;
  --info-bg: #16243f;
  --slate-bg: #232d30;
  --slate: #c3ccce;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 4px; letter-spacing: -0.01em; }
p { margin: 0 0 8px; color: var(--muted); }

button, input, select, textarea { font-family: inherit; font-size: 14px; }
body { transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }

.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

.icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.icon-sm { width: 15px; height: 15px; }

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

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.2s ease;
  z-index: 40;
}
.sidebar-nav { position: relative; padding: 4px 0; }
.nav-indicator {
  position: absolute; left: 10px; width: 2.5px; border-radius: 2px; background: var(--primary);
  top: 0; height: 0; opacity: 0; pointer-events: none; z-index: 1;
}

.brand {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand .name { font-weight: 700; font-size: 14px; line-height: 1.3; letter-spacing: 0.01em; }
.brand .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

.nav-group { margin-bottom: 14px; padding: 0 10px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 4px 10px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 4px; color: var(--muted);
  cursor: pointer; font-size: 13.5px; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
  border-left: 2px solid transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.nav-item .icon { color: var(--muted); transition: color var(--dur-fast) var(--ease); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item.active .icon { color: var(--primary); }

.sidebar-footer { margin-top: auto; padding: 14px 16px 0; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-chip .name { font-weight: 700; font-size: 13px; line-height: 1.3; }
.user-chip .role { font-size: 11px; color: var(--muted); }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.topbar h1 { font-size: 16px; font-weight: 700; }
.topbar .right { display: flex; align-items: center; gap: 8px; }

.menu-toggle {
  display: none;
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  width: 32px; height: 32px; cursor: pointer; color: var(--text);
}

.content { padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(13, 95, 92, 0.25); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: none; border: none; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--radius); font-size: 13px; position: relative; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-title { font-size: 13.5px; font-weight: 700; margin-bottom: 12px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.stat-card .top-row { display: flex; align-items: center; justify-content: space-between; }
.stat-card .label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .icon { color: var(--primary); opacity: 0.55; }
.stat-card .value { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.action-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); cursor: pointer;
  display: flex; flex-direction: column; gap: 10px;
  transition: box-shadow var(--dur) var(--ease-out), transform var(--dur) var(--ease-out), border-color var(--dur-fast) var(--ease);
}
.action-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--primary); }
.action-card .icon-slot {
  width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.action-card h3 { font-size: 15px; }
.action-card p { font-size: 12.5px; margin: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 640px; background: var(--surface); }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; font-weight: 600;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.empty-row td { text-align: center; color: var(--muted); padding: 30px; cursor: default; }
.empty-row:hover { background: transparent; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 3px;
  font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge-new, .badge-open { background: var(--info-bg); color: var(--info); }
.badge-assigned { background: #eee9f7; color: #5b3aa8; }
[data-theme="dark"] .badge-assigned { background: #241c3a; color: #b7a6e6; }
.badge-inprogress { background: var(--warning-bg); color: var(--warning); }
.badge-resolved { background: var(--success-bg); color: var(--success); }
.badge-closed { background: var(--slate-bg); color: var(--slate); }
.badge-reopened { background: var(--danger-bg); color: var(--danger); }

.badge-low { background: var(--success-bg); color: var(--success); }
.badge-medium { background: var(--info-bg); color: var(--info); }
.badge-high { background: var(--warning-bg); color: var(--warning); }
.badge-critical { background: var(--danger-bg); color: var(--danger); }

.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--slate-bg); color: var(--slate); }

.escalated-flag { color: var(--danger); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
label .req { color: var(--danger); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); outline: none; }
textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.file-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.file-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 12.5px;
}
.file-chip .remove { cursor: pointer; color: var(--danger); font-weight: 700; }
.file-chip .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .file-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Attachment lightbox ---------- */
.lightbox {
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.lightbox-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600;
}
.lightbox img { display: block; max-width: 90vw; max-height: calc(90vh - 44px); object-fit: contain; background: var(--surface-2); }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.filter-field label { margin-bottom: 0; font-size: 11px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; position: relative; }
.tab-btn {
  padding: 8px 14px; border: none; background: none; color: var(--muted); font-weight: 600; font-size: 13px;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur-fast) var(--ease);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); }
.tab-indicator { position: absolute; bottom: -1px; left: 0; height: 2px; width: 0; background: var(--primary); pointer-events: none; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 25, 25, 0.45); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 720px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.no-motion .modal-overlay { animation: overlayIn var(--dur) var(--ease-out); }
.no-motion .modal { animation: modalIn var(--dur) var(--ease-out); }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-sm { max-width: 440px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 15px; }
.modal-body { padding: 20px; max-height: 72vh; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.close-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 16px 20px; border-left: 2px solid var(--border); margin-left: 4px;
}
.timeline li:last-child { border-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -5px; top: 3px; width: 8px; height: 8px;
  background: var(--primary); border: 2px solid var(--surface);
}
.timeline .t-action { font-weight: 700; font-size: 13px; }
.timeline .t-meta { font-size: 11px; color: var(--muted); margin: 2px 0 4px; }
.timeline .t-remarks { font-size: 12.5px; background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; }

/* ---------- Notifications ---------- */
.notif-panel {
  position: absolute; right: 0; top: 40px; width: 320px; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 60;
}
.notif-item { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.notif-item:last-child { border-bottom: none; }
.notif-item .msg { margin-bottom: 3px; }
.notif-item .time { font-size: 11px; color: var(--muted); }
.notif-item.unread { background: var(--primary-light); }
.notif-wrap { position: relative; }
.notif-dot {
  position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; border-radius: 8px;
  font-size: 10px; font-weight: 700; min-width: 15px; height: 15px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: var(--radius); padding: 11px 14px; box-shadow: var(--shadow-lg); font-size: 13px; min-width: 240px;
}
.no-motion .toast { animation: slideIn 0.2s ease; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Bar chart (pure CSS) ---------- */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 36px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-track { background: var(--surface-2); border-radius: 2px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); width: 0; }

/* ---------- Login page ---------- */
.login-shell { min-height: 100vh; display: flex; }
.login-aside {
  flex: 1.1; position: relative; overflow: hidden; background: var(--primary-dark);
  color: #eef7f6; display: flex; flex-direction: column; justify-content: center;
  padding: 64px; min-width: 0;
}
.login-aside::before {
  content: ""; position: absolute; width: 620px; height: 620px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.09), transparent 70%);
  top: -260px; right: -220px; pointer-events: none;
}
.login-aside::after {
  content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.06), transparent 70%);
  bottom: -200px; left: -160px; pointer-events: none;
}
.login-aside .mark { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.75; margin-bottom: 22px; position: relative; }
.login-aside h1 { font-size: 30px; font-weight: 700; max-width: 420px; line-height: 1.25; position: relative; color: #fff; }
.login-aside p { color: rgba(238, 247, 246, 0.75); max-width: 380px; margin-top: 10px; font-size: 14px; position: relative; }
.login-points { list-style: none; margin: 28px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; position: relative; }
.login-points li { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; color: rgba(238, 247, 246, 0.9); }
.login-points .icon { color: #fff; opacity: 0.85; margin-top: 1px; }
.login-form-panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 30px 28px; }
.login-brand { margin-bottom: 22px; text-align: left; border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.login-brand h1 { font-size: 17px; }
.login-error { background: var(--danger-bg); color: var(--danger); padding: 9px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
@media (max-width: 860px) {
  .login-aside { display: none; }
}

/* ---------- View transitions ---------- */
.view-fade { animation: viewFade var(--dur) var(--ease-out); }
@keyframes viewFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 12.5px; }
.text-center { text-align: center; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding: 14px; }
  .bar-row { grid-template-columns: 100px 1fr 32px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { max-width: 100%; }
  .topbar h1 { font-size: 14px; }
}
