:root {
  color-scheme: dark;
  --bg: #06111f;
  --bg-deep: #040c16;
  --surface: #0b1b2d;
  --surface-2: #10233a;
  --surface-3: #142a43;
  --line: rgba(171, 201, 231, .12);
  --line-strong: rgba(171, 201, 231, .2);
  --text: #f4f8fc;
  --muted: #91a5ba;
  --blue: #3995ff;
  --cyan: #52d9e1;
  --green: #48d5a1;
  --amber: #f7ba5c;
  --orange: #ff865e;
  --red: #fa5f72;
  --violet: #a989ff;
  --shadow: 0 28px 70px rgba(0, 0, 0, .28);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -5%, rgba(57, 149, 255, .12), transparent 28rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }

[hidden] { display: none !important; }

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

.brand-mark {
  position: relative;
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(82, 217, 225, .28);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(57, 149, 255, .2), rgba(82, 217, 225, .06));
}

.brand-mark::before,
.brand-mark::after,
.brand-mark i::before,
.brand-mark i::after {
  content: "";
  position: absolute;
  inset: 9px 19px;
  border-radius: 2px;
  background: var(--cyan);
  transform: rotate(45deg);
  opacity: .9;
}

.brand-mark::after { transform: rotate(-45deg); }
.brand-mark i::before { transform: rotate(90deg); background: var(--blue); }
.brand-mark i::after { transform: rotate(0deg); background: var(--blue); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 20% 25%, rgba(82, 217, 225, .09), transparent 25rem),
    radial-gradient(circle at 80% 70%, rgba(57, 149, 255, .12), transparent 30rem),
    linear-gradient(145deg, var(--bg-deep), #07182a);
}

.login-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 54px 54px;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: rgba(9, 26, 44, .88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.login-brand, .side-brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.login-brand strong, .side-brand strong { display: block; font-size: 16px; letter-spacing: .01em; }
.login-brand small, .side-brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }

.login-copy { margin: 44px 0 28px; }
.login-copy h1 { margin: 0; font-size: clamp(28px, 7vw, 36px); line-height: 1.1; letter-spacing: -.035em; }
.login-copy > p:last-child { margin: 14px 0 0; color: var(--muted); }

.form-stack { display: grid; gap: 17px; }
label > span, .date-field span { display: block; margin: 0 0 7px; color: #bdcddd; font-size: 12px; font-weight: 650; }

input, select {
  min-height: 43px;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  outline: none;
  background: rgba(255, 255, 255, .035);
  transition: border-color .2s, box-shadow .2s, background .2s;
}

input { width: 100%; padding: 10px 13px; }
select { padding: 9px 34px 9px 12px; }
select { color-scheme: dark; }
select option { color: var(--text); background: var(--surface-2); }
input::placeholder { color: #647a90; }
input:focus, select:focus { border-color: rgba(57, 149, 255, .7); box-shadow: 0 0 0 3px rgba(57, 149, 255, .12); background: rgba(255,255,255,.055); }

.form-error { margin: -5px 0 0; color: #ff8797; font-size: 12px; }
.login-footnote { margin: 24px 0 0; color: #647a90; font-size: 11px; text-align: center; }

.button, .icon-button, .text-button {
  border: 0;
  border-radius: 11px;
  background: none;
}

.button {
  min-height: 42px;
  padding: 9px 16px;
  font-weight: 750;
  transition: transform .15s, border-color .2s, background .2s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .65; transform: none; }
.button.full { width: 100%; }
.button.primary { color: #fff; background: linear-gradient(135deg, #368ff4, #176dc8); box-shadow: 0 11px 28px rgba(35, 127, 225, .2); }
.button.secondary { border: 1px solid rgba(57,149,255,.28); background: rgba(57,149,255,.11); }
.button.danger { border: 1px solid rgba(245,108,108,.32); background: rgba(245,108,108,.1); color: #ff9b9b; margin-left: 6px; }
.compose-panel { margin-bottom: 18px; }
.compose-hint { color: var(--muted); font-size: 12px; }
.compose-form { display: grid; gap: 14px; }
.compose-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.compose-form input, .compose-form textarea, .compose-form select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; color: var(--text); background: rgba(255,255,255,.04); font: inherit; }
.compose-form textarea { resize: vertical; min-height: 100px; }
.muted-detail { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.compose-options { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)) auto; gap: 12px; align-items: end; }
.compose-submit { min-height: 42px; white-space: nowrap; }
@media (max-width: 800px) { .compose-options { grid-template-columns: 1fr 1fr; } .compose-submit { grid-column: 1 / -1; } }
.button.ghost { border: 1px solid var(--line-strong); background: rgba(255,255,255,.025); }
.button.small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
.text-button { padding: 5px; color: #6fb1ff; font-size: 12px; font-weight: 750; }
.text-button:hover { color: #a4d0ff; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,.025); font-size: 18px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 248px;
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(5, 15, 26, .96);
  backdrop-filter: blur(18px);
}

.side-brand { padding: 0 9px; color: inherit; text-decoration: none; }
.side-nav { display: grid; gap: 7px; margin-top: 50px; }
.nav-item {
  width: 100%;
  min-height: 47px;
  padding: 9px 11px;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: #8297ad;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  transition: color .2s, border-color .2s, background .2s;
}
.nav-item:hover { color: #d7e5f3; background: rgba(255,255,255,.025); }
.nav-item.active { color: #fff; border-color: rgba(57,149,255,.18); background: linear-gradient(90deg, rgba(57,149,255,.16), rgba(57,149,255,.04)); }
.nav-icon { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.035); font-size: 15px; }
.nav-item.active .nav-icon { color: var(--cyan); background: rgba(57,149,255,.14); }
.nav-count { min-width: 21px; padding: 2px 6px; border-radius: 20px; color: #201200; background: var(--amber); font-size: 10px; text-align: center; }

.side-footer { margin-top: auto; padding: 17px 10px 4px; display: flex; align-items: center; gap: 10px; color: var(--muted); border-top: 1px solid var(--line); }
.side-footer strong, .side-footer small { display: block; }
.side-footer strong { color: #aebfd0; font-size: 11px; }
.side-footer small { margin-top: 2px; font-size: 10px; }
.system-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--green); box-shadow: 0 0 11px rgba(72,213,161,.6); }

.workspace { min-height: 100vh; margin-left: 248px; }
.topbar {
  min-height: 96px;
  padding: 22px clamp(22px, 4vw, 48px);
  display: flex;
  align-items: center;
  gap: 17px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 17, 31, .72);
  backdrop-filter: blur(16px);
}
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.025em; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.menu-button { display: none; }
.content { padding: clamp(22px, 4vw, 44px); }
.view { display: none; }
.view.active { display: block; animation: view-in .22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card {
  position: relative;
  min-height: 162px;
  padding: 22px;
  display: flex;
  flex-wrap: wrap;
  align-content: space-between;
  justify-content: space-between;
  gap: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(17, 40, 65, .92), rgba(8, 25, 43, .92));
  box-shadow: 0 14px 35px rgba(0,0,0,.12);
}
.metric-card::before { content: ""; position: absolute; width: 110px; height: 110px; margin: -68px 0 0 -68px; border-radius: 50%; background: currentColor; opacity: .055; }
.metric-card > div span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card > div strong { display: block; margin-top: 10px; color: var(--text); font-size: 31px; line-height: 1; letter-spacing: -.04em; }
.metric-card > i { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 11px; background: rgba(255,255,255,.06); font-style: normal; }
.metric-card > small { width: 100%; color: #6f859b; font-size: 10px; }
.metric-card > small b { color: #aebfd0; font-weight: 700; }
.accent-blue { color: var(--blue); }.accent-amber { color: var(--amber); }.accent-violet { color: var(--violet); }.accent-green { color: var(--green); }

.overview-grid { margin-top: 16px; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: rgba(10, 28, 47, .77); box-shadow: 0 16px 40px rgba(0,0,0,.1); }
.panel-header { padding: 21px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.priority-grid { padding: 22px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 11px; }
.priority-card { padding: 18px 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.022); }
.priority-card::before { content: ""; width: 8px; height: 8px; display: block; margin-bottom: 18px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.priority-card span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.priority-card strong { display: block; margin-top: 7px; color: var(--text); font-size: 26px; }
.priority-card.normal { color: var(--blue); }.priority-card.high { color: var(--amber); }.priority-card.emergency { color: var(--orange); }.priority-card.critical { color: var(--red); }

.preview-list { min-height: 190px; padding: 8px 20px; display: grid; align-content: start; }
.preview-item { padding: 13px 2px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--line); }
.preview-item:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; color: var(--cyan); background: rgba(82,217,225,.08); font-weight: 800; }
.preview-item > div { min-width: 0; flex: 1; }
.preview-item strong, .primary-cell strong { display: block; overflow: hidden; color: #dfeaf5; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.preview-item small, .primary-cell small { display: block; margin-top: 3px; overflow: hidden; color: #70869c; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.loading-block { color: var(--muted); place-items: center; font-size: 12px; }

.table-panel { margin-top: 16px; overflow: hidden; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: #70869c; background: rgba(3, 13, 23, .2); font-size: 9px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; white-space: nowrap; }
td { color: #adbdcd; font-size: 11px; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(255,255,255,.018); }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { height: 130px; color: #70869c; text-align: center; }
.primary-cell { max-width: 390px; min-width: 200px; }
.primary-cell strong { font-size: 12px; }
.primary-cell small { max-width: 430px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
.muted { color: #6e849a; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid currentColor; border-radius: 20px; font-size: 9px; font-weight: 800; letter-spacing: .045em; text-transform: uppercase; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.normal { color: #61aaff; background: rgba(57,149,255,.07); }.badge.high { color: #f7ba5c; background: rgba(247,186,92,.07); }.badge.emergency { color: #ff8c66; background: rgba(255,134,94,.07); }.badge.critical { color: #fa6b7d; background: rgba(250,95,114,.07); }
.badge.approved, .badge.read { color: #55d7a6; background: rgba(72,213,161,.07); }.badge.pending, .badge.unread { color: #f7ba5c; background: rgba(247,186,92,.07); }.badge.rejected { color: #ff9b9b; background: rgba(245,108,108,.08); }.badge.expired { color: #8297ad; background: rgba(130,151,173,.07); }

.read-cell { min-width: 110px; }
.read-cell strong { color: #dae7f3; font-size: 11px; }
.progress { width: 86px; height: 4px; margin-top: 7px; overflow: hidden; border-radius: 8px; background: rgba(255,255,255,.075); }
.progress i { height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--cyan)); }

.toolbar { padding: 17px 18px; display: flex; align-items: end; flex-wrap: wrap; gap: 10px; border-bottom: 1px solid var(--line); }
.search-field { min-width: 240px; flex: 1; position: relative; }
.search-field span { position: absolute; left: 13px; top: 11px; color: #657c92; }
.search-field input { padding-left: 35px; }
.date-field { width: 145px; }
.date-field span { margin-bottom: 4px; color: #70869c; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.date-field input { min-height: 40px; padding: 8px 10px; }
.message-toolbar select, .toolbar > select { min-height: 40px; }

.pagination { min-height: 60px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: #72879c; border-top: 1px solid var(--line); font-size: 10px; }
.pagination div { display: flex; gap: 7px; }
.pagination button { min-width: 34px; height: 32px; border: 1px solid var(--line); border-radius: 9px; color: #9db0c3; background: rgba(255,255,255,.025); }
.pagination button:disabled { cursor: default; opacity: .35; }

.modal { width: min(450px, calc(100% - 30px)); padding: 0; color: var(--text); border: 1px solid var(--line-strong); border-radius: 20px; background: #0b1b2d; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(1, 7, 13, .76); backdrop-filter: blur(5px); }
.modal form { padding: 29px; }
.modal-icon { width: 43px; height: 43px; margin-bottom: 23px; display: grid; place-items: center; border-radius: 13px; color: var(--green); background: rgba(72,213,161,.1); font-size: 18px; }
.modal h2 { margin: 0; font-size: 24px; letter-spacing: -.025em; }
.modal-subtitle, .receipt-header p:last-child { margin: 9px 0 21px; color: var(--muted); font-size: 12px; }
.modal-actions { margin-top: 25px; display: flex; justify-content: flex-end; gap: 9px; }

.receipts-modal { width: min(900px, calc(100% - 30px)); }
.receipt-dialog-content { max-height: min(760px, calc(100vh - 40px)); display: flex; flex-direction: column; }
.receipt-header { padding: 24px 26px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.receipt-header h2 { font-size: 20px; }
.receipt-header p:last-child { margin-bottom: 0; }
.receipt-header .icon-button { flex: none; }
.segmented { margin: 0 26px 17px; padding: 4px; align-self: flex-start; display: flex; gap: 3px; border: 1px solid var(--line); border-radius: 10px; background: rgba(0,0,0,.12); }
.segmented button { padding: 7px 12px; color: #7f94a9; border: 0; border-radius: 7px; background: none; font-size: 10px; font-weight: 750; }
.segmented button.active { color: #e6f0f9; background: var(--surface-3); }
.receipt-table-wrap { border-top: 1px solid var(--line); }

.toast {
  position: fixed;
  z-index: 100;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100% - 44px));
  padding: 13px 16px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: #dce9f5;
  background: #10263e;
  box-shadow: 0 18px 40px rgba(0,0,0,.3);
  font-size: 12px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: rgba(250,95,114,.4); color: #ffd4da; background: #351722; }
.mobile-backdrop { display: none; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .app-shell.nav-open .sidebar { transform: none; }
  .workspace { margin-left: 0; }
  .menu-button { display: grid; }
  .mobile-backdrop { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.55); }
  .app-shell.nav-open + .mobile-backdrop { display: block; }
  .topbar { min-height: 82px; padding: 17px 20px; }
  .content { padding: 20px; }
  .priority-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .login-shell { padding: 15px; }
  .login-card { padding: 26px 22px; }
  .login-copy { margin-top: 35px; }
  .top-actions .button { display: none; }
  .topbar h1 { font-size: 20px; }
  .content { padding: 14px; }
  .metric-grid { grid-template-columns: 1fr; gap: 10px; }
  .metric-card { min-height: 138px; }
  .priority-grid { padding: 15px; }
  .panel-header { padding: 17px; }
  .toolbar { align-items: stretch; }
  .toolbar > *, .search-field, .date-field { width: 100%; min-width: 0; }
  .message-toolbar .button { width: 100%; }
  th, td { padding: 13px 14px; }
  .modal form { padding: 23px; }
  .receipt-header { padding: 20px; }
  .segmented { margin-left: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
