:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #66706d;
  --soft: #f3f5f1;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --line: #dde3dc;
  --line-strong: #cbd4cf;
  --brand: #101716;
  --brand-2: #183a32;
  --blue: #2f5c9f;
  --gold: #b97821;
  --danger: #b13d3d;
  --danger-soft: #fff0ee;
  --ok: #24714d;
  --ok-soft: #eaf7ef;
  --warn: #9c6b18;
  --warn-soft: #fff6df;
  --shadow: 0 18px 48px rgba(22, 32, 29, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--brand);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  padding: 8px 12px;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
}

button.ghost {
  color: var(--brand);
  background: transparent;
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

.hidden {
  display: none !important;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #101716 0%, #182721 54%, #f3f5f1 54%, #f7f8f5 100%);
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 54px;
  height: 54px;
}

.login-panel h1,
.topbar h1 {
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-panel p,
.topbar p {
  margin: 0;
  color: var(--muted);
}

.login-panel form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}

.error {
  min-height: 20px;
  color: var(--danger) !important;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 260px minmax(0, 1fr);
  background: linear-gradient(90deg, var(--brand) 0 260px, var(--paper) 260px);
}

.sidebar {
  display: flex;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  color: #f7fbf6;
  background:
    linear-gradient(180deg, #101716 0%, #12241f 62%, #1b342e 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand img {
  width: 42px;
  height: 42px;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span {
  display: block;
  color: #b8c7c0;
  font-size: 13px;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tabs button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  border-color: rgba(255, 255, 255, 0.12);
  color: #dfe9e4;
  background: transparent;
  text-align: left;
}

.tabs button::before {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  color: #d7e2dd;
  background: rgba(255, 255, 255, 0.05);
  content: attr(data-short);
  font-size: 13px;
  font-weight: 800;
}

.tabs button.active {
  border-color: rgba(236, 188, 92, 0.82);
  color: #101716;
  background: #f4e5b7;
}

.tabs button.active::before {
  border-color: rgba(16, 23, 22, 0.18);
  color: #101716;
  background: rgba(255, 255, 255, 0.58);
}

.sidebar #changePasswordBtn {
  margin-top: auto;
}

.sidebar .ghost {
  border-color: rgba(255, 255, 255, 0.24);
  color: #f7fbf6;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 2;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -24px -24px 18px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid rgba(221, 227, 220, 0.78);
  background: rgba(247, 248, 245, 0.9);
  backdrop-filter: blur(14px);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notification-trigger {
  position: relative;
  min-width: 64px;
}

.notification-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--paper);
  border-radius: 999px;
  padding: 0 5px;
  color: #fff;
  background: var(--warn);
  font-size: 11px;
  line-height: 1;
}

.notification-badge.danger {
  background: var(--danger);
}

.top-meta {
  color: var(--muted);
  font-size: 13px;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.status-pill.ok,
.badge.ok {
  border-color: rgba(36, 113, 77, 0.28);
  color: var(--ok);
  background: var(--ok-soft);
}

.status-pill.danger,
.badge.danger {
  border-color: rgba(177, 61, 61, 0.28);
  color: var(--danger);
  background: var(--danger-soft);
}

.status-pill.neutral,
.badge.neutral {
  color: var(--blue);
  background: #edf3ff;
}

.content {
  display: grid;
  gap: 14px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: #eef7f2;
  background: linear-gradient(135deg, #14231f 0%, #213932 100%);
  box-shadow: var(--shadow);
}

.hero-panel.danger {
  background: linear-gradient(135deg, #351819 0%, #6b2c2c 100%);
}

.eyebrow {
  color: #b9cfc5;
  font-size: 12px;
  font-weight: 800;
}

.hero-panel h2 {
  margin: 8px 0 4px;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.hero-panel p {
  margin: 0;
  color: #c9d8d0;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 112px);
  gap: 8px;
  align-content: end;
}

.hero-stats span {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px;
  color: #c9d8d0;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
}

.hero-stats strong {
  color: #fff;
  font-size: 24px;
  line-height: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.panel,
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card {
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 15px;
}

.metric-card span,
.metric-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  overflow-wrap: anywhere;
  font-size: 26px;
  line-height: 1.05;
}

.panel {
  overflow: hidden;
}

.card {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.panel h2,
.card h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.status-ok {
  color: var(--ok);
}

.status-warn {
  color: var(--warn);
}

.status-danger {
  color: var(--danger);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  background: #fbfcfa;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

td.actions {
  min-width: 250px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.inline-actions button,
.table-actions button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px;
}

.control-grid > div {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.control-grid span,
.control-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.control-grid strong {
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.08;
}

.mobile-list {
  display: none;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  color: var(--ok);
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.notice {
  margin: 16px;
  border: 1px solid #efd599;
  border-radius: 8px;
  padding: 12px;
  color: #74500f;
  background: var(--warn-soft);
}

.pre {
  overflow: auto;
  max-height: 560px;
  white-space: pre-wrap;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  background: #fbfcfa;
  color: #2f3935;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
}

dialog {
  width: 100%;
  max-width: none;
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(16, 23, 22, 0.56);
  backdrop-filter: blur(4px);
}

.dialog-card {
  width: min(460px, calc(100vw - 32px));
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}

.dialog-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.dialog-card p {
  color: var(--muted);
}

.password-form {
  display: grid;
  gap: 14px;
}

.dialog-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.notification-dialog-card {
  display: grid;
  gap: 12px;
  width: min(620px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 40px));
  overflow: hidden;
}

.notification-head,
.notification-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.notification-head h2 {
  margin: 0 0 4px;
}

.notification-head p {
  margin: 0;
  color: var(--muted);
}

.notification-actions {
  justify-content: flex-start;
}

.notification-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.notification-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.notification-item.unread {
  border-color: var(--line-strong);
  background: #fff;
  box-shadow: 0 8px 22px rgba(22, 32, 29, 0.06);
}

.notification-item.read {
  opacity: 0.72;
}

.notification-item strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.notification-item p {
  margin: 5px 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.notification-item small {
  color: var(--muted);
}

.notification-severity {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.notification-severity.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.notification-severity.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.notification-severity.neutral {
  color: var(--blue);
  background: #edf3ff;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid rgba(16, 23, 22, 0.12);
  border-radius: 8px;
  padding: 12px 14px;
  color: #f7fbf6;
  background: rgba(16, 23, 22, 0.94);
  box-shadow: var(--shadow);
  font-size: 14px;
}

@media (max-width: 1080px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .hero-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    background: var(--paper);
  }

  .app-shell {
    display: block;
    min-height: 100vh;
    background: var(--paper);
  }

  .sidebar {
    position: fixed;
    inset: auto 10px 10px;
    z-index: 5;
    height: auto;
    border: 1px solid rgba(16, 23, 22, 0.12);
    border-radius: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 14px 32px rgba(22, 32, 29, 0.18);
    backdrop-filter: blur(18px);
  }

  .brand,
  .sidebar .ghost {
    display: none;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
  }

  .tabs button {
    display: grid;
    min-width: 0;
    min-height: 54px;
    justify-items: center;
    gap: 2px;
    border: 0;
    border-radius: 6px;
    padding: 5px 3px;
    color: var(--muted);
    background: transparent;
    font-size: 11px;
    text-align: center;
  }

  .tabs button::before {
    width: 26px;
    height: 22px;
    border: 0;
    color: currentColor;
    background: transparent;
    font-size: 15px;
  }

  .tabs button.active {
    color: var(--brand);
    background: #eef2e8;
  }

  .main {
    padding: 0 12px 92px;
  }

  .topbar {
    align-items: flex-start;
    margin: 0 -12px 12px;
    padding: calc(14px + env(safe-area-inset-top)) 14px 14px;
    border-bottom: 0;
    background: linear-gradient(180deg, #101716 0%, #172821 100%);
    color: #fff;
  }

  .topbar h1 {
    margin-top: 8px;
    font-size: 27px;
  }

  .topbar p {
    max-width: 230px;
    color: #b8c7c0;
    font-size: 13px;
  }

  .top-actions {
    display: grid;
    justify-items: end;
    gap: 8px;
  }

  .top-meta {
    max-width: 118px;
    color: #b8c7c0;
    font-size: 11px;
    text-align: right;
  }

  #refreshBtn {
    min-height: 36px;
    border-color: rgba(255, 255, 255, 0.18);
    color: #101716;
    background: #f4e5b7;
  }

  .notification-trigger,
  #topPasswordBtn {
    min-height: 34px;
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
  }

  .notification-badge {
    border-color: #172821;
  }

  .content {
    gap: 12px;
  }

  .hero-panel {
    padding: 16px;
  }

  .hero-panel h2 {
    font-size: 32px;
  }

  .hero-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hero-stats span {
    min-width: 0;
    padding: 8px;
    font-size: 11px;
  }

  .hero-stats strong {
    font-size: 22px;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric-card {
    min-height: 96px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: 22px;
  }

  .control-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .control-grid > div {
    padding: 11px;
  }

  .control-grid strong {
    font-size: 18px;
  }

  .panel-head {
    align-items: flex-start;
    min-height: 0;
    padding: 12px;
  }

  .panel-head h2 {
    padding-top: 3px;
  }

  .table-actions {
    gap: 6px;
  }

  .table-actions button {
    min-height: 30px;
    padding: 4px 8px;
  }

  .desktop-table {
    display: none;
  }

  .mobile-list {
    display: grid;
    gap: 8px;
    padding: 10px;
  }

  .mini-card,
  .account-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
  }

  .mini-card {
    display: grid;
    gap: 5px;
  }

  .mini-card span,
  .mini-card p,
  .account-card span,
  .account-card small {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
  }

  .mini-card strong {
    overflow-wrap: anywhere;
  }

  .account-list {
    padding: 10px;
  }

  .account-card {
    display: grid;
    gap: 12px;
  }

  .account-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  .account-card-head strong {
    display: block;
    overflow-wrap: anywhere;
  }

  .account-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .account-kpis span {
    display: grid;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px;
    background: #fbfcfa;
  }

  .account-kpis b {
    font-size: 15px;
  }

  .inline-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-actions button {
    width: 100%;
  }

  .empty-state {
    padding: 16px;
  }

  .notice {
    margin: 12px;
  }

  .pre {
    max-height: 440px;
    padding: 12px;
    font-size: 12px;
  }

  dialog[open] {
    display: grid;
    min-height: 100vh;
    align-items: end;
  }

  .dialog-card {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .notification-dialog-card {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

  .notification-head,
  .notification-actions,
  .notification-item {
    display: grid;
    grid-template-columns: 1fr;
  }

  .notification-list {
    max-height: calc(100vh - 230px);
  }

  .toast {
    right: 12px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 380px) {
  .top-meta {
    display: none;
  }

  .tabs button {
    font-size: 10px;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}
