/* ==========================================================
   AWG Panel — интерфейс в духе Apple (macOS / iOS)
   Плоские поверхности без обводок, скруглённые виджеты,
   сгруппированные списки как в «Настройках», один акцент.
   ========================================================== */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-lg: 20px;
  --r: 14px;
  --r-sm: 10px;
  --green: #30d158;
  --amber: #ff9f0a;
  --red: #ff453a;
}

/* Тёмная — по умолчанию */
:root, [data-theme="dark"] {
  --bg: #05070B;
  --sidebar: #05070B;
  --card: #0B1018;
  --card-2: #131A24;
  --fill: rgba(120, 130, 150, 0.16);
  --fill-2: rgba(120, 130, 150, 0.11);
  --fill-3: rgba(120, 130, 150, 0.07);
  --sep: rgba(140, 150, 170, 0.14);
  --text: #F5F7FA;
  --text-2: rgba(245, 247, 250, 0.6);
  --text-3: rgba(245, 247, 250, 0.32);
  --accent: #00296b;
  --accent-fill: rgba(0, 41, 107, 0.20);
  --blur-bg: rgba(11, 16, 24, 0.78);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f2f2f7;
  --sidebar: #eaeaef;
  --card: #ffffff;
  --card-2: #ffffff;
  --fill: rgba(120, 120, 128, 0.16);
  --fill-2: rgba(120, 120, 128, 0.10);
  --fill-3: rgba(120, 120, 128, 0.07);
  --sep: rgba(60, 60, 67, 0.14);
  --text: #1d1d1f;
  --text-2: rgba(60, 60, 67, 0.62);
  --text-3: rgba(60, 60, 67, 0.3);
  --accent: #00296b;
  --accent-fill: rgba(0, 41, 107, 0.14);
  --blur-bg: rgba(249, 249, 251, 0.82);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%; margin: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.4;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
button { font-family: inherit; }
::selection { background: var(--accent-fill); }

/* ---------- Поля ввода ---------- */
input, select {
  width: 100%; background: var(--fill); color: var(--text);
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 10px 12px; font: inherit; letter-spacing: inherit; outline: none;
  transition: border-color .15s, background .15s;
  -webkit-appearance: none; appearance: none;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus { border-color: var(--accent); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238e8e93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px; padding-right: 30px;
}

/* Переключатель как в iOS */
input.switch {
  width: 42px; height: 26px; padding: 0; border: 0; border-radius: 13px;
  background: var(--fill); position: relative; cursor: pointer; flex-shrink: 0;
  transition: background .2s;
}
input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .2s;
}
input.switch:checked { background: var(--green); }
input.switch:checked::after { transform: translateX(16px); }

/* ---------- Кнопки ---------- */
.btn {
  border: 0; border-radius: 9px; padding: 8px 16px;
  font: inherit; font-weight: 500; letter-spacing: inherit;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, opacity .15s, transform .08s;
}
.btn:active { transform: scale(0.97); opacity: .85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .92; }
.btn-secondary { background: var(--fill); color: var(--text); }
.btn-secondary:hover { background: var(--fill-hover, rgba(120,120,128,.32)); }
.btn-danger { background: transparent; color: var(--red); }
.btn-danger:hover { background: rgba(255, 69, 58, 0.12); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }

.error-text { color: var(--red); font-size: 13px; text-align: left; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { opacity: .8; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--fill-2); border: 0; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn.floating { position: absolute; top: calc(16px + env(safe-area-inset-top, 0px)); right: 16px; width: 36px; height: 36px; }
.icon-btn.floating svg { width: 18px; height: 18px; }

/* ---------- Вход ---------- */
.login-screen {
  min-height: 100vh; min-height: 100dvh; padding: 24px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.login-card { width: 100%; max-width: 320px; text-align: center; }
.login-logo {
  width: 76px; height: 76px; margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }
/* На тёмном фоне сам логотип (тёмно-синий) теряется — подкладываем светлую
   подложку, чтобы он читался так же чётко, как на светлой теме */
[data-theme="dark"] .login-logo {
  background: #EDEFF3; border-radius: 20px; padding: 10px; width: 92px; height: 92px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.login-title { margin: 0; line-height: 1.1; }
.login-title .l1 {
  display: block; font-size: 14px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent);
}
.login-title .l2 {
  display: block; font-size: 42px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent);
}
.login-sub { color: var(--text-2); margin: 10px 0 28px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-form input { padding: 13px 14px; font-size: 15px; }
#login-form .btn { margin-top: 8px; padding: 12px; font-size: 15px; }

/* ---------- Каркас ---------- */
.app-shell { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 212px; flex-shrink: 0; background: var(--sidebar);
  padding: 20px 10px 12px; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 22px; font-size: 14px; font-weight: 600; letter-spacing: -0.015em; }
.brand-mark {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
[data-theme="dark"] .brand-mark {
  background: #EDEFF3; border-radius: 8px; padding: 3px; width: 30px; height: 30px;
}
.nav-section { font-size: 11px; font-weight: 600; color: var(--text-3); padding: 0 9px 6px; letter-spacing: 0.01em; }
.nav-links { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-links a {
  display: flex; align-items: center; gap: 9px; height: 30px; padding: 0 9px;
  border-radius: 7px; font-size: 13.5px; font-weight: 500; color: var(--text);
  transition: background .12s;
}
.nav-links a svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.nav-links a:hover { background: var(--fill-3); }
.nav-links a.active { background: var(--fill); }

.sidebar-footer { display: flex; align-items: center; gap: 9px; padding: 10px 6px 0; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--fill);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--text-2); flex-shrink: 0; text-transform: uppercase;
}
.whoami { flex: 1; min-width: 0; line-height: 1.25; }
#whoami-name { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mobile-tabbar { display: none; }

.content { flex: 1; overflow-y: auto; padding: 32px 40px 60px; }
.content > * { max-width: 1180px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; min-height: 36px; }
.page-title { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; margin: 0; line-height: 1.15; }
.page-sub { color: var(--text-2); margin: -10px 0 22px; max-width: 620px; }
.page-meta { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

.back-link { display: inline-flex; align-items: center; color: var(--accent); font-size: 13.5px; margin: 0 0 10px -4px; }
.back-link svg { width: 18px; height: 18px; }

/* ---------- Виджеты обзора ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.widget {
  position: relative; background: var(--card); border-radius: var(--r-lg);
  padding: 16px 18px; min-height: 132px; display: flex; flex-direction: column; min-width: 0;
}
.w-1 { grid-column: span 1; } .w-2 { grid-column: span 2; } .w-4 { grid-column: span 4; }
.widget-title { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 12px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.035em; line-height: 1; font-variant-numeric: tabular-nums; }
.big small { font-size: 15px; font-weight: 500; color: var(--text-2); letter-spacing: -0.01em; margin-left: 2px; }
.widget-sub { font-size: 12.5px; color: var(--text-2); margin-top: auto; padding-top: 12px; font-variant-numeric: tabular-nums; }
.bar { height: 4px; border-radius: 2px; background: var(--fill); margin-top: 12px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 2px; transition: width .5s ease; }
.bar.warn > div { background: var(--amber); } .bar.danger > div { background: var(--red); }

.ring-row { display: flex; align-items: center; gap: 14px; flex: 1; }
.ring { width: 74px; height: 74px; flex-shrink: 0; }
.ring-bg { fill: none; stroke: var(--fill); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring.warn .ring-fg { stroke: var(--amber); } .ring.danger .ring-fg { stroke: var(--red); }
.ring-text { font-size: 21px; font-weight: 700; fill: var(--text); letter-spacing: -0.03em; }
.ring-main { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ring-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

.cores { display: flex; align-items: flex-end; gap: 6px; height: 74px; }
.core { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; min-width: 0; }
.core-bar { flex: 1; width: 100%; max-width: 26px; background: var(--fill); border-radius: 5px; display: flex; align-items: flex-end; overflow: hidden; }
.core-bar > div { width: 100%; background: var(--accent); border-radius: 5px; transition: height .5s ease; min-height: 2px; }
.core span { font-size: 10px; color: var(--text-3); }

.iface-list { display: flex; flex-direction: column; }
.iface { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--sep); }
.iface:first-child { border-top: 0; padding-top: 0; }
.iface b { font-weight: 600; font-family: var(--mono); font-size: 13px; }
.iface small { color: var(--text-2); font-size: 12.5px; }
.iface .r { text-align: right; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.widget-empty { color: var(--text-2); font-size: 13px; }
.widget-empty code { font-family: var(--mono); font-size: 12px; background: var(--fill-2); padding: 2px 6px; border-radius: 5px; }

/* режим настройки виджетов */
.widget.editing { cursor: grab; box-shadow: inset 0 0 0 1.5px var(--fill); }
.widget.editing:active { cursor: grabbing; }
.widget.dragging { opacity: .35; }
.widget.over { box-shadow: inset 0 0 0 2px var(--accent); }
.widget-tools { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 12px; }
.tool-group { display: flex; gap: 4px; }
.tool-btn {
  width: 26px; height: 26px; border-radius: 7px; border: 0; background: var(--fill);
  color: var(--text); font-size: 15px; line-height: 1; cursor: pointer;
}
.tool-btn:hover { background: var(--fill-hover, rgba(120,120,128,.32)); }
.tool-btn.del { color: var(--red); }
.segmented { display: inline-flex; background: var(--fill); border-radius: 8px; padding: 2px; }
.segmented button {
  border: 0; background: none; color: var(--text-2); font-size: 11.5px; font-weight: 500;
  padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.segmented button.on { background: var(--card-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
[data-theme="light"] .segmented button.on { background: #fff; }
.chips-title { margin: 26px 4px 10px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; background: var(--card); color: var(--text); padding: 7px 13px; border-radius: 100px; font-size: 13px; cursor: pointer; }
.chip:hover { background: var(--fill); }

/* ---------- Таблицы ---------- */
.table-wrap { background: var(--card); border-radius: var(--r-lg); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--sep); white-space: nowrap; vertical-align: middle; }
th { color: var(--text-2); font-weight: 500; font-size: 12px; padding-top: 11px; padding-bottom: 11px; }
td { font-variant-numeric: tabular-nums; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--fill-3); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
td small { color: var(--text-2); font-size: 12px; }
td.chev-cell { width: 28px; padding-left: 0; color: var(--text-3); }
td.chev-cell svg { width: 16px; height: 16px; }
.muted { color: var(--text-2); }
.empty { text-align: center; color: var(--text-2); padding: 44px 16px !important; }
.mini-bar { width: 96px; margin-top: 7px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--fill); color: var(--text); }
.badge-awg2 { background: var(--accent-fill); color: var(--accent); }

.status-dot { display: inline-flex; align-items: center; gap: 7px; }
.status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.status-active::before, .online::before { background: var(--green); }
.status-paused::before { background: var(--amber); }
.status-limited::before, .status-expired::before { background: var(--red); }

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

/* ---------- Страница конфигурации: сгруппированные списки ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 28px; align-items: start; }
.qr-card { background: var(--card); border-radius: var(--r-lg); padding: 16px; text-align: center; }
.qr-card img { width: 100%; border-radius: 12px; background: #fff; padding: 10px; }
.qr-card .muted { padding: 30px 8px; font-size: 13px; }
.qr-actions { display: flex; gap: 8px; margin-top: 12px; }
.qr-actions .btn { flex: 1; }
.group-title { font-size: 12px; font-weight: 500; color: var(--text-2); margin: 26px 8px 8px; }
.group-title.first { margin-top: 0; }
.group { background: var(--card); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 16px; min-height: 46px; border-bottom: 1px solid var(--sep); }
.row:last-child { border-bottom: 0; }
.row .lbl { flex-shrink: 0; }
.row .val { flex: 1; min-width: 0; display: flex; justify-content: flex-end; align-items: center; gap: 10px; color: var(--text-2); text-align: right; }
.row .val.mono { font-family: var(--mono); font-size: 12.5px; }
.row input, .row select {
  width: auto; max-width: 240px; background: transparent; color: var(--text-2);
  text-align: right; padding: 6px 8px; margin-right: -8px; border-radius: 8px;
}
.row select { background-position: right 8px center; padding-right: 26px; text-align: right; text-align-last: right; }
.row input:hover, .row select:hover { background: var(--fill-3); }
.row input:focus, .row select:focus { background: var(--fill-2); color: var(--text); border-color: transparent; }
.row.log { padding: 10px 16px; align-items: flex-start; }
.row.log small { color: var(--text-2); display: block; margin-top: 1px; }
.row.log .val { flex: 0 0 auto; font-size: 12.5px; white-space: nowrap; }
label.row { cursor: pointer; }
.row-btn { width: 100%; text-align: left; background: none; border: 0; padding: 13px 16px; font-size: 14px; color: var(--accent); cursor: pointer; }
.row-btn:hover { background: var(--fill-3); }
.row-btn.danger { color: var(--red); }
.save-bar { display: flex; justify-content: flex-end; margin-top: 16px; }

/* ---------- Модальные окна ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .18s ease;
}
.modal {
  width: 100%; max-width: 380px; max-height: 90vh; overflow-y: auto;
  background: var(--card); border-radius: 22px; padding: 24px; animation: pop .22s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal h3 { margin: 0 0 18px; font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.modal .field { margin-bottom: 14px; }
.modal label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.modal .group { background: var(--fill-2); }
.modal .group label.row { margin: 0; font-size: 14px; color: var(--text); font-weight: 400; }
.modal p { color: var(--text-2); font-size: 13px; margin: -8px 0 14px; }
.modal img { width: 100%; border-radius: 12px; background: #fff; padding: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 22px; }
.modal-actions .btn { flex: 1; padding: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 100px;
  font-size: 13.5px; font-weight: 500; z-index: 200; max-width: 90vw; animation: fade .2s ease;
}
.loading { padding: 60px 0; text-align: center; color: var(--text-2); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==========================================================
   Планшет и телефон
   ========================================================== */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .w-4 { grid-column: span 2; }
  .detail { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }

  .mobile-tabbar {
    display: flex; align-items: stretch; justify-content: space-around;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--blur-bg);
    -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
    border-top: 1px solid var(--sep);
    padding: 7px 2px calc(7px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-tabbar a, .tab-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
    color: var(--text-3); font-size: 10px; font-weight: 500; padding: 3px 0;
    background: none; border: 0; border-radius: 0; width: auto; height: auto;
  }
  .mobile-tabbar svg { width: 22px; height: 22px; }
  .mobile-tabbar a.active { color: var(--accent); }
  .tab-btn::after { content: "Тема"; }

  .content { padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
  .content > * { max-width: none; }
  .page-title { font-size: 32px; }
  .page-header { margin-bottom: 18px; }
  .dash-grid { gap: 10px; }
  .widget { padding: 14px 16px; min-height: 118px; }
  .big { font-size: 28px; }
  .ring { width: 62px; height: 62px; }
  .ring-text { font-size: 22px; }

  .table-wrap { background: transparent; border-radius: 0; overflow: visible; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody tr { background: var(--card); border-radius: var(--r); padding: 4px 16px; margin-bottom: 10px; }
  tbody tr:hover { background: var(--card); }
  td { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; white-space: normal; text-align: right; }
  td::before { content: attr(data-label); color: var(--text-2); font-size: 13px; text-align: left; flex-shrink: 0; }
  td.row-actions { flex-wrap: wrap; justify-content: flex-start; padding: 12px 0 8px; }
  td.row-actions::before, td.empty::before, td.chev-cell { display: none; }
  td.empty { display: block; text-align: center; }
  .mini-bar { margin-left: auto; }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px)); animation: sheet .25s ease; }
  input, select { font-size: 16px; }
  .row input, .row select { max-width: 55vw; }
}

@media (max-width: 380px) { .dash-grid { grid-template-columns: 1fr; } .w-2, .w-4 { grid-column: span 1; } }
