@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Syne:wght@600;700;800&display=swap");

:root {
  --bg: #09090b;
  --bg-elev: #0f1014;
  --ink: #f4f4f5;
  --muted: #a1a1aa;
  --muted-2: #71717a;
  --surface: #12131a;
  --surface-2: #181922;
  --surface-3: #1f212c;
  --border: #272833;
  --border-2: #3f4254;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --accent-ink: #041018;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.1);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.1);
  --danger: #fb7185;
  --danger-bg: rgba(251, 113, 133, 0.1);
  --info-bg: rgba(56, 189, 248, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 0 0 1px rgba(255,255,255,0.03), 0 16px 40px rgba(0,0,0,0.45);
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --display: "Syne", "Plus Jakarta Sans", sans-serif;
  --control-h: 44px;
  --panel-sm: 540px;
  --panel-md: 700px;
  --panel-lg: 860px;
  --sidebar-w: 256px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #3f4254 #09090b;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #3f4254;
  border-radius: 99px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: #5b5f75; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: #7dd3fc; text-decoration: underline; }

h1, h2, h3 {
  margin: 0 0 .7rem;
  color: var(--ink);
  letter-spacing: -0.03em;
}
h1 {
  font-family: var(--display);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.15;
}
h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
h3 {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 1.4rem 0 .8rem;
}

.muted { color: var(--muted); }
.page-lead {
  margin: -.4rem 0 1.4rem;
  max-width: 40rem;
  color: var(--muted);
  font-size: .95rem;
}

code {
  display: inline-block;
  max-width: 100%;
  padding: .2rem .45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: #bae6fd;
  font-size: .82em;
  word-break: break-all;
}

/* ——— Shell ——— */
.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 45% at 0% 0%, rgba(14, 165, 233, 0.11), transparent 55%),
    radial-gradient(ellipse 50% 35% at 100% 0%, rgba(99, 102, 241, 0.06), transparent 50%),
    linear-gradient(180deg, #0b0c10 0%, var(--bg) 28%, #08080a 100%);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  width: var(--sidebar-w);
  height: 100vh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.2rem .85rem 1rem;
  background: rgba(10, 11, 15, 0.92);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2e3140 transparent;
}

.sidebar .brand {
  margin: 0 .35rem 1.25rem;
  padding: .15rem .25rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar .brand-title {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #fff;
  line-height: 1.1;
}
.sidebar .brand-sub {
  display: block;
  margin-top: .4rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.sidebar .nav-section {
  margin: 1.05rem .55rem .3rem;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #52525b;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 40px;
  margin-bottom: 2px;
  padding: .4rem .7rem;
  border-radius: 9px;
  color: #d4d4d8;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,.04);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--accent-soft);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar nav a.nav-logout {
  margin-top: auto;
  margin-top: 1rem;
  padding-top: .9rem;
  border-top: 1px solid var(--border);
  border-radius: 0 0 9px 9px;
  color: var(--muted-2);
}
.sidebar nav a.nav-logout:hover { color: #fda4af; }

.nav-badge {
  margin-left: auto;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 .35rem;
  border-radius: 99px;
  background: var(--warning);
  color: #1c1400;
  font-size: .65rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.7rem 2.75rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.35rem;
  padding-bottom: 1.05rem;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; }

.user-meta {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  max-width: 100%;
  padding: .35rem .8rem .35rem .35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: .82rem;
}
.user-meta .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(145deg, #0284c7, #38bdf8);
  color: #021018;
  font-size: .7rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-meta strong { color: var(--ink); font-weight: 700; }
.user-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ——— Cards ——— */
.card {
  margin-bottom: 1rem;
  padding: 1.2rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card > h2:first-child {
  margin: 0 0 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}

.panel {
  width: 100%;
  max-width: var(--panel-md);
}
.panel--sm { max-width: var(--panel-sm); }
.panel--lg { max-width: var(--panel-lg); }

.grid { display: grid; gap: .95rem; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat {
  min-height: 92px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(56,189,248,.06), transparent 55%),
    var(--surface-2);
}
.stat .label {
  color: var(--muted-2);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.stat .value {
  margin-top: .4rem;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
}

/* ——— Tables ——— */
.table-wrap { width: 100%; overflow-x: auto; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .88rem;
}
th, td {
  padding: .72rem .75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  color: var(--muted-2);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}
tbody tr:hover td { background: rgba(56, 189, 248, 0.035); }
tbody tr:last-child td { border-bottom: 0; }

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 38px;
  padding: .4rem .95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: .84rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: .15s ease;
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-2);
  text-decoration: none;
}
.btn-primary {
  border-color: transparent;
  background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 100%);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #7dd3fc 0%, #0284c7 100%);
  color: var(--accent-ink);
}
.btn-success { background: var(--success-bg); border-color: rgba(74,222,128,.3); color: var(--success); }
.btn-danger { background: var(--danger-bg); border-color: rgba(251,113,133,.3); color: var(--danger); }
.btn-warning { background: var(--warning-bg); border-color: rgba(251,191,36,.3); color: var(--warning); }
.btn-sm { min-height: 30px; padding: .25rem .6rem; font-size: .76rem; }
.btn-group { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }

.form-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}

/* ——— Forms ——— */
.form { width: 100%; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: .95rem;
}

.field {
  grid-column: span 12;
  display: flex;
  flex-direction: column;
  gap: .38rem;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}
.field--6 { grid-column: span 6; }
.field--5 { grid-column: span 5; }
.field--4 { grid-column: span 4; }
.field--3 { grid-column: span 3; }
.field--8 { grid-column: span 8; }

.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form input[type="url"],
.form input[type="date"],
.form select,
.form textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: var(--control-h);
  margin: 0;
  padding: 0 .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #0a0b10;
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form select {
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2371717a' d='M1.4.6L6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .9rem center;
}
.form textarea {
  height: auto;
  min-height: 108px;
  padding: .75rem .85rem;
  line-height: 1.45;
  resize: vertical;
}
.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.16);
}
.form select option { background: #12131a; color: var(--ink); }
.form input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(.7);
  cursor: pointer;
}

.check {
  display: flex;
  align-items: center;
  gap: .7rem;
  min-height: var(--control-h);
  padding: 0 .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Settings-style toggle row (long labels) */
.option-row {
  grid-column: span 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0;
  padding: .95rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
}
.option-row__copy {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  min-width: 0;
}
.option-row__title {
  color: var(--ink);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.3;
}
.option-row__desc {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 500;
  line-height: 1.4;
}
.option-row input[type="checkbox"] {
  position: relative;
  width: 44px;
  height: 24px;
  margin: 0;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: #0a0b10;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.option-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #a1a1aa;
  transition: transform .15s ease, background .15s ease;
}
.option-row input[type="checkbox"]:checked {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent);
}
.option-row input[type="checkbox"]:checked::after {
  transform: translateX(20px);
  background: var(--accent);
}
.option-row:hover {
  border-color: var(--border-2);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}
.checkbox-grid .check { min-height: 42px; margin: 0; }

/* Operator permissions */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem;
}
.perm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: 0;
  min-height: 48px;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s ease, background .15s ease;
}
.perm-item:hover {
  border-color: var(--border-2);
  background: rgba(56, 189, 248, 0.05);
}
.perm-item__label {
  color: var(--ink);
  font-size: .86rem;
  font-weight: 600;
  line-height: 1.3;
}
.perm-item input[type="checkbox"] {
  position: relative;
  width: 40px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: #0a0b10;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.perm-item input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #a1a1aa;
  transition: transform .15s ease, background .15s ease;
}
.perm-item input[type="checkbox"]:checked {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent);
}
.perm-item input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: var(--accent);
}

.form > label:not(.field):not(.check) {
  display: flex;
  flex-direction: column;
  gap: .38rem;
  margin-bottom: .95rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}

.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.actions-bar .muted { margin: 0; max-width: 38rem; }
.actions-bar select {
  min-width: 200px;
  height: 38px;
  padding: 0 .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #0a0b10;
  color: var(--ink);
  font: inherit;
}

.empty {
  padding: 1.5rem 0;
  color: var(--muted);
  text-align: center;
}
.due-soon { color: var(--warning); font-weight: 700; }
.overdue { color: var(--danger); font-weight: 700; }

.alert {
  margin-bottom: 1rem;
  padding: .8rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: .9rem;
}
.alert-success { background: var(--success-bg); border-color: rgba(74,222,128,.28); color: #bbf7d0; }
.alert-error { background: var(--danger-bg); border-color: rgba(251,113,133,.28); color: #fecdd3; }
.alert-warning { background: var(--warning-bg); border-color: rgba(251,191,36,.28); color: #fde68a; }
.alert-info { background: var(--info-bg); border-color: rgba(56,189,248,.28); color: #bae6fd; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: .14rem .48rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-active { background: var(--success-bg); border-color: rgba(74,222,128,.28); color: var(--success); }
.badge-inactive { background: var(--danger-bg); border-color: rgba(251,113,133,.28); color: var(--danger); }
.badge-currency { background: var(--accent-soft); border-color: rgba(56,189,248,.28); color: var(--accent); }

/* ——— Auth ——— */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 60% 50% at 20% 20%, rgba(14,165,233,.2), transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 75%, rgba(99,102,241,.12), transparent 55%),
    #07080c;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem 1.7rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(18, 19, 26, 0.96);
  box-shadow: var(--shadow);
}
.install-card { max-width: 560px; }
.auth-eyebrow {
  display: inline-block;
  margin-bottom: .7rem;
  color: var(--accent);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.auth-card h1 {
  margin-bottom: .35rem;
  color: #fff;
  font-size: 2rem;
}
.auth-card > .muted { margin-bottom: 1.3rem; }
.auth-card .btn-primary,
.install-card .form-actions .btn-primary {
  width: 100%;
  min-height: 44px;
}
.install-card h2 {
  margin: 1.3rem 0 .85rem;
  padding-top: .9rem;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .2rem; }
  .sidebar .nav-section { width: 100%; }
  .sidebar nav a.nav-logout { width: 100%; }
  .main { padding: 1.1rem 1rem 2rem; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .field--6, .field--5, .field--4, .field--3, .field--8 { grid-column: span 12; }
  .checkbox-grid,
  .perm-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.55rem; }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .field--5, .field--4, .field--3 { grid-column: span 6; }
}
