:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #17202a;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #1f7a68;
  --accent-2: #0f5f90;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --shadow: 0 8px 28px rgba(25, 32, 45, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101418;
  --surface: #171d23;
  --surface-2: #202831;
  --text: #edf2f7;
  --muted: #a8b3c2;
  --line: #303b47;
  --accent: #55c7aa;
  --accent-2: #76b7e8;
  --danger: #ff8a7a;
  --warn: #f7b267;
  --ok: #77d7a8;
  --shadow: 0 8px 28px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.icon { width: 38px; padding: 0; }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  border-radius: 7px;
  padding: 8px 10px;
}

textarea { min-height: 88px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
a { color: var(--accent-2); }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-box h1, .page-title h1 { margin: 0; font-size: 24px; }
.login-box p, .muted { color: var(--muted); }
.form-grid { display: grid; gap: 12px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { font-weight: 750; font-size: 18px; margin-bottom: 18px; }
.nav { display: grid; gap: 6px; }
.nav button {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
}
.nav button.active { background: var(--surface-2); color: var(--accent); }

.main { padding: 22px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.compact-actions button { min-height: 34px; padding: 6px 10px; }
.page-title { display: grid; gap: 4px; }
.page-title p { margin: 0; color: var(--muted); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 { margin: 0; }

.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: 1.1fr .9fr; }
.filters { grid-template-columns: repeat(6, minmax(130px, 1fr)); align-items: end; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel { padding: 16px; }
.card { padding: 14px; }
.metric { display: grid; gap: 4px; }
.metric strong { font-size: 26px; }
.metric span { color: var(--muted); font-size: 13px; }

.table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr.row-highlighted td { background: rgba(102, 112, 133, .14); }
[data-theme="dark"] tbody tr.row-highlighted td { background: rgba(168, 179, 194, .13); }

.sort-header {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.danger { color: var(--danger); }

.phone-cell {
  display: grid;
  gap: 3px;
}

.esim-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.esim-icon {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 4px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0;
}

.drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 20;
}
.drawer.open { display: block; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.38); }
.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  width: min(760px, 100%);
  height: 100%;
  overflow: auto;
  background: var(--surface);
  padding: 18px;
  border-left: 1px solid var(--line);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-form { display: grid; gap: 14px; }
.fields-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fields-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.warning { color: var(--warn); font-size: 13px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nav button { text-align: center; padding: 8px 6px; font-size: 13px; }
  .main { padding: 14px; }
  .stats-grid, .two-col, .filters, .fields-2, .fields-3 { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  table { min-width: 860px; font-size: 14px; }
  th, td { padding: 8px 9px; white-space: nowrap; }
  th:nth-child(3), td:nth-child(3),
  th:nth-child(7), td:nth-child(7) {
    min-width: 124px;
  }
}
