:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #050505;
  --muted: #65676b;
  --line: #e4e6eb;
  --hover: #e9ebee;
  --primary: #00a884;
  --primary-dark: #008c6e;
  --primary-soft: #e6f7f2;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fff4e0;
  --info: #1b6fd8;
  --info-soft: #e8f1fd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.16), 0 2px 4px rgba(0, 0, 0, 0.08);
  --topbar: 56px;
  --sidebar: 272px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.block { display: block; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar); z-index: 30;
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; }
.brand-mark .icon { width: 20px; height: 20px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: inline-grid; place-items: center;
  background: var(--hover); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: #dcdfe4; }
.menu-btn { display: none; }

/* ---------- Sidebar ---------- */
.shell { padding-top: var(--topbar); }
.sidebar {
  position: fixed; top: var(--topbar); bottom: 0; left: 0; width: var(--sidebar); z-index: 20;
  padding: 12px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; background: var(--bg);
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px;
  font-weight: 600; color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item .nav-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--muted); box-shadow: var(--shadow); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav-item.active .nav-icon { background: var(--primary); color: #fff; box-shadow: none; }
.nav-sep { height: 1px; background: #d8dadf; margin: 8px 10px; }
.nav-foot { margin-top: auto; padding: 8px 2px 4px; }
.wa-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.wa-card:hover { background: #fafafa; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #bcc0c4; flex: none; }
.status-dot.ok { background: #31a24c; box-shadow: 0 0 0 3px #dff3e4; }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.scrim { display: none; }

/* ---------- Page ---------- */
.main { margin-left: var(--sidebar); min-height: calc(100vh - var(--topbar)); }
.page { max-width: 1080px; margin: 0 auto; padding: 24px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; color: var(--muted); }
.crumb { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.crumb:hover { color: var(--text); }
.crumb .icon { width: 16px; height: 16px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-main { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: grid; gap: 16px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 8px; }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 8px 16px 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.link-more { color: var(--primary-dark); font-weight: 600; font-size: 14px; }
.link-more:hover { text-decoration: underline; }

/* ---------- Stats ---------- */
.stats { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.stat { display: flex; align-items: center; gap: 12px; padding: 16px; }
.stat-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.stat-icon.green { background: var(--primary-soft); color: var(--primary-dark); }
.stat-icon.blue { background: var(--info-soft); color: var(--info); }
.stat-icon.amber { background: var(--warn-soft); color: var(--warn); }
.stat-icon.gray { background: var(--hover); color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 0; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn .icon { width: 18px; height: 18px; }
.btn-secondary { background: var(--hover); color: var(--text); }
.btn-secondary:hover { background: #dcdfe4; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fbd5d1; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
form.inline { display: inline; margin: 0; }

/* ---------- Alerts & badges ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; background: var(--info-soft); color: #123; }
.alert .icon { margin-top: 1px; }
.alert.success { background: var(--primary-soft); }
.alert.success .icon { color: var(--primary-dark); }
.alert.danger, .alert.error { background: var(--danger-soft); }
.alert.danger .icon, .alert.error .icon { color: var(--danger); }
.alert.warn { background: var(--warn-soft); }
.alert.warn .icon { color: var(--warn); }
.alert a { font-weight: 600; text-decoration: underline; }
.alert-close { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0; }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--primary-soft); color: var(--primary-dark); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--info-soft); color: var(--info); }

/* ---------- Avatars & lists ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; flex: none; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }
img.avatar { object-fit: cover; background: var(--hover); }
.avatar.xs { width: 26px; height: 26px; font-size: 10px; border: 2px solid var(--surface); margin-left: -8px; }
.avatar.xs:first-child { margin-left: 0; }
.avatar.more { background: var(--hover); color: var(--muted); }
.avatar-stack { display: inline-flex; align-items: center; flex: none; }
.stack-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stack-line > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tone-0 { background: #1b74e4; } .tone-1 { background: #00a884; } .tone-2 { background: #e4405f; } .tone-3 { background: #f5a623; }
.tone-4 { background: #8e44ad; } .tone-5 { background: #16a085; } .tone-6 { background: #d35400; } .tone-7 { background: #2c3e50; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--hover); flex: none; display: grid; place-items: center; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--bg); font-size: 13px; font-weight: 600; }
.chip .icon { width: 14px; height: 14px; }
a.chip:hover { background: var(--hover); }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 40px 20px; }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); }
.empty-icon .icon { width: 30px; height: 30px; }
.empty h2 { margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 16px; }

/* ---------- Folders & photos ---------- */
.folder-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.folder-card { overflow: hidden; display: flex; flex-direction: column; transition: box-shadow 0.15s; }
.folder-card:hover { box-shadow: var(--shadow-lg); }
.folder-cover { aspect-ratio: 16 / 10; background: linear-gradient(135deg, #e6f7f2, #d9ecfb); display: grid; place-items: center; color: var(--primary-dark); overflow: hidden; }
.folder-cover img { width: 100%; height: 100%; object-fit: cover; }
.folder-cover .icon { width: 42px; height: 42px; stroke-width: 1.5; }
.folder-card .card-body { padding: 12px 14px 14px; }
.folder-meta { display: flex; gap: 12px; color: var(--muted); font-size: 13px; margin-top: 4px; flex-wrap: wrap; }
.folder-new { border: 2px dashed #cfd3d8; background: transparent; box-shadow: none; display: grid; place-items: center; min-height: 220px; color: var(--muted); font-weight: 600; cursor: pointer; font: inherit; }
.folder-new:hover { background: var(--surface); color: var(--primary-dark); border-color: var(--primary); }
.folder-new .icon { width: 32px; height: 32px; margin: 0 auto 6px; display: block; }
.photo-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--hover); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-num { position: absolute; left: 6px; top: 6px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.photo form { position: absolute; right: 6px; top: 6px; opacity: 0; transition: opacity 0.15s; }
.photo:hover form, .photo:focus-within form { opacity: 1; }
@media (hover: none) { .photo form { opacity: 1; } }
.photo-del { width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; display: grid; place-items: center; cursor: pointer; }
.photo-del .icon { width: 16px; height: 16px; }
.dropzone { border: 2px dashed #cfd3d8; border-radius: var(--radius); padding: 24px; text-align: center; background: #fafbfc; transition: 0.15s; cursor: pointer; }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .empty-icon { margin-bottom: 8px; }
.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 12px; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width 0.2s; }
.meter { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 8px; }
.meter span { display: block; height: 100%; background: var(--primary); }
.meter.low span { background: #f5a623; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 8px; overflow-x: auto; }
.tab { padding: 12px 12px 10px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.tab .badge { height: 20px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field > label, .label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=search], select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid #ccd0d5; border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.inline-fields { display: flex; align-items: center; gap: 8px; }
.inline-fields input { max-width: 110px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.day-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.day-chip input { position: absolute; opacity: 0; pointer-events: none; }
.day-chip span { display: inline-grid; place-items: center; min-width: 48px; height: 36px; padding: 0 10px; border-radius: 999px; background: var(--hover); font-weight: 600; cursor: pointer; }
.day-chip input:checked + span { background: var(--primary); color: #fff; }
.day-chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--primary-soft); }
.choice { display: grid; gap: 8px; }
.choice label { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 400; }
.choice label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin-top: 3px; accent-color: var(--primary); }
.choice b { display: block; }
.picker { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.picker-tools { display: flex; gap: 8px; padding: 8px; background: var(--bg); align-items: center; }
.picker-list { max-height: 360px; overflow-y: auto; }
.picker-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; cursor: pointer; }
.picker-item + .picker-item { border-top: 1px solid var(--line); }
.picker-item:hover { background: #fafafa; }
.picker-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.switch-btn { width: 44px; height: 24px; border-radius: 999px; border: 0; background: #ccd0d5; position: relative; cursor: pointer; padding: 0; }
.switch-btn::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch-btn.on { background: var(--primary); }
.switch-btn.on::after { left: 23px; }

/* ---------- Tables / log ---------- */
.log-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) 170px auto; gap: 12px; align-items: center; padding: 10px 16px; }
.log-row + .log-row { border-top: 1px solid var(--line); }
.log-row .thumb { width: 48px; height: 48px; }
.pager { display: flex; justify-content: center; gap: 8px; padding: 12px; }

/* ---------- Menus & dialogs ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 40; }
.menu-list form { margin: 0; }
.menu-item { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; border: 0; background: none; font: inherit; font-weight: 500; color: var(--text); cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-head { padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.modal { border: 0; border-radius: var(--radius); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(244, 244, 244, 0.8); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.settings-nav { padding: 8px; }
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; font-weight: 600; }
.settings-nav a:hover { background: var(--hover); }
.settings-nav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.qr-box { display: grid; place-items: center; padding: 16px; min-height: 240px; }
.qr-box img { width: 280px; max-width: 100%; border-radius: 12px; border: 8px solid #fff; box-shadow: var(--shadow-lg); }
.pair-code { font: 700 32px/1 ui-monospace, Consolas, monospace; letter-spacing: 6px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); padding: 28px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand .brand-mark { width: 56px; height: 56px; margin: 0 auto 12px; }
.auth-brand .brand-mark .icon { width: 28px; height: 28px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-grid; }
  .brand-name { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; background: var(--surface); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(0, 0, 0, 0.3); z-index: 15; }
  .main { margin-left: 0; }
  .page { padding: 16px 12px 48px; }
  .grid-2, .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .log-row { grid-template-columns: 48px minmax(0, 1fr) auto; }
  .log-row .hide-sm { display: none; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .topbar-actions .hide-sm { display: none; }
}
