:root {
  --bg: #161c24; --panel: #212b36; --panel2: #28323f; --line: #2f3b48; --text: #fff; --muted: #919eab; --dim: #637381;
  --green: #22c55e; --green-bg: #22c55e29; --red: #ff5630; --red-bg: #ff563029; --amber: #ffab00; --amber-bg: #ffab0029;
  --violet: #c4b5fd; --mint: #bbf7d0; --radius: 16px; --side: 240px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f6f8; --panel: #fff; --panel2: #f9fafb; --line: #e5e8eb; --text: #1c252e; --muted: #637381; --dim: #919eab;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Public Sans", Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--muted); } .dim { color: var(--dim); } .small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* layout */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow: auto; border-right: 1px dashed var(--line); padding: 20px 12px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 0 8px 18px; }
.logo i { width: 34px; height: 34px; border-radius: 10px; background: var(--green); display: grid; place-items: center; color: #111; font-style: normal; }
.side .sec { font-size: 11px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; padding: 16px 12px 6px; }
.side a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.side a:hover { background: #919eab14; }
.side a.on { background: var(--green-bg); color: var(--green); font-weight: 600; }
.side a.sub { padding-left: 44px; font-size: 13px; }
.side a.sub.on { background: none; color: var(--text); }
.side svg { width: 20px; height: 20px; flex: none; }
.top { display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 16px 40px; }
.main { padding: 8px 40px 60px; max-width: 1400px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.crumbs { margin-top: 8px; color: var(--muted); } .crumbs b { color: var(--text); font-weight: 400; } .crumbs i { margin: 0 10px; font-style: normal; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: transparent; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #919eab14; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); border-color: #ff563066; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: #919eab14; color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.field { position: relative; display: block; margin-top: 12px; }
.field > span { position: absolute; top: -8px; left: 12px; padding: 0 4px; background: var(--panel); font-size: 12px; color: var(--muted); z-index: 1; }
.input, select.input, textarea.input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: transparent; outline: 0; }
textarea.input { height: auto; min-height: 90px; padding: 12px 14px; resize: vertical; }
.input:focus { border-color: var(--text); }
select.input { appearance: none; background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'><path fill='%23919eab' d='M12 15.5 6.5 10l1.4-1.4 4.1 4.1 4.1-4.1L17.5 10z'/></svg>") no-repeat right 12px center; padding-right: 36px; }
select.input option { background: var(--panel); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 12px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; cursor: pointer; margin: 0; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 22px; background: var(--dim); transition: .2s; }
.switch i::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { left: 19px; }
.setting { display: flex; justify-content: space-between; gap: 24px; align-items: center; padding: 14px 0; }
.setting + .setting { border-top: 1px dashed var(--line); }
.radio { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; }
.radio input, .check input { accent-color: var(--green); width: 18px; height: 18px; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-right: 16px; cursor: pointer; }
.label { font-weight: 600; margin-top: 22px; }
.label:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; min-height: 48px; align-items: center; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 10px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600; }
.chip button { border: 0; width: 18px; height: 18px; border-radius: 50%; background: #637381; color: var(--bg); cursor: pointer; font-size: 11px; line-height: 1; padding: 0; }
.chips select { border: 0; background: transparent; outline: 0; flex: 1; min-width: 140px; height: 30px; }

/* cards & table */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: 0 0 2px #0003, 0 12px 24px -4px #0000001f; }
.card.pad { padding: 32px; }
.card + .card { margin-top: 24px; }
.tabs { display: flex; gap: 40px; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { display: flex; align-items: center; gap: 8px; padding: 14px 0 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; }
.tabs a.on { color: var(--text); border-color: var(--text); }
.count { min-width: 24px; height: 24px; padding: 0 6px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; }
.c-all { background: var(--text); color: var(--bg); } .c-active { background: var(--green-bg); color: var(--green); }
.c-new { background: var(--amber-bg); color: var(--amber); } .c-stopped { background: var(--red-bg); color: var(--red); }
.filters { display: grid; grid-template-columns: minmax(180px, 360px) 1fr; gap: 16px; padding: 20px; }
.search { position: relative; } .search svg { position: absolute; left: 14px; top: 14px; width: 20px; color: var(--dim); }
.search input { padding-left: 44px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; background: var(--panel2); color: var(--muted); font-weight: 600; padding: 16px; white-space: nowrap; }
td { padding: 16px; border-bottom: 1px dashed var(--line); vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover td { background: #919eab0a; }
.app-cell { display: flex; align-items: center; gap: 16px; }
.app-icon { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; background: var(--panel2); flex: none; display: grid; place-items: center; font-weight: 800; color: var(--muted); }
.flag { width: 28px; height: 20px; border-radius: 3px; object-fit: cover; vertical-align: middle; background: var(--panel2); }
.badge { display: inline-flex; height: 24px; padding: 0 8px; align-items: center; border-radius: 6px; font-size: 12px; font-weight: 700; }
.b-active { background: var(--green-bg); color: var(--green); } .b-new { background: var(--amber-bg); color: var(--amber); } .b-stopped { background: var(--red-bg); color: var(--red); }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.menu { position: absolute; right: 0; top: 100%; z-index: 20; min-width: 180px; padding: 4px; border-radius: 10px; background: var(--panel); box-shadow: 0 0 2px #0006, 0 20px 40px -4px #0006; }
.menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: #919eab14; } .menu button.red { color: var(--red); }
.rel { position: relative; }

/* editor with phone preview */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.sticky { position: sticky; top: 24px; }
.phone { width: 300px; height: 600px; border: 10px solid #000; border-radius: 40px; overflow: hidden; background: linear-gradient(#c3eef3, #f7d3cd); position: relative; }
.phone iframe { width: 390px; height: 808px; border: 0; transform: scale(.718); transform-origin: 0 0; background: #000; }
.phone-tabs { display: flex; gap: 6px; justify-content: center; margin-bottom: 12px; }
.notif { position: absolute; left: 10px; right: 10px; top: 110px; padding: 10px 12px 12px; background: #212b36ee; color: #fff; border-radius: 16px; font-size: 12px; }
.notif .h { display: flex; align-items: center; gap: 6px; color: #dfe3e8; }
.notif .h i { width: 16px; height: 16px; border-radius: 50%; background: #0019ff; flex: none; }
.notif .h img { width: 16px; height: 16px; border-radius: 50%; }
.notif .t { font-weight: 700; margin-top: 8px; word-break: break-word; }
.notif .x { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.notif .img { margin-top: 8px; width: 100%; border-radius: 8px; }
.notif .ic { float: right; width: 36px; height: 36px; border-radius: 6px; margin-left: 8px; object-fit: cover; }
.uploader { display: flex; gap: 16px; align-items: flex-start; margin-top: 12px; }
.up { position: relative; display: grid; place-items: center; border-radius: 10px; background: var(--panel2); border: 1px dashed var(--line); cursor: pointer; color: var(--dim); overflow: hidden; }
.up img { width: 100%; height: 100%; object-fit: cover; }
.up input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.up .del { position: absolute; top: 4px; right: 4px; z-index: 2; width: 20px; height: 20px; border-radius: 50%; border: 0; background: #000a; color: #fff; cursor: pointer; font-size: 11px; }
.dropzone { display: block; border: 1px dashed var(--line); border-radius: 12px; padding: 32px; text-align: center; background: var(--panel2); cursor: pointer; position: relative; }
.dropzone.over { border-color: var(--green); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.rule { display: grid; grid-template-columns: 140px 130px 1fr 36px; gap: 10px; align-items: center; margin-top: 10px; }
.rule .input { height: 42px; }
.code { background: var(--panel2); border-radius: 8px; padding: 10px 12px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }
.note { padding: 12px 16px; border-radius: 10px; background: #00b8d929; color: #61f3f3; font-size: 13px; }
.note.warn { background: var(--amber-bg); color: var(--amber); }
.fullpage { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow: auto; }
.fullpage .bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--bg); }
.fullpage .body { max-width: 1060px; margin: 0 auto; padding: 8px 24px 80px; }
.savebar { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* stats */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { padding: 20px; } .kpi b { display: block; font-size: 26px; margin-top: 4px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding: 20px 24px 0; }
.bars div { flex: 1; background: var(--green); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars div span { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--dim); white-space: nowrap; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal .dow { text-align: center; padding: 12px; font-weight: 600; border-bottom: 1px solid var(--line); }
.cal .day { min-height: 112px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day .n { text-align: right; font-size: 13px; padding: 2px 4px; }
.cal .day.out .n { color: var(--dim); }
.cal .day.today { background: #919eab14; } .cal .day.today .n span { background: var(--red); color: #fff; border-radius: 50%; padding: 2px 6px; }
.ev { display: block; margin-top: 3px; padding: 2px 6px; border-radius: 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #1c252e; cursor: pointer; }
.ev b { margin-right: 4px; }
.ev.off { opacity: .45; }
.more { font-size: 11px; color: var(--muted); padding: 2px 4px; }

#toast { position: fixed; right: 24px; bottom: 24px; z-index: 99; display: flex; flex-direction: column; gap: 8px; }
#toast div { padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 10px 30px #0006; max-width: 420px; }
#toast div.err { background: var(--red); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; }
.login .card { width: 360px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; } .side { display: none; }
  .main, .top { padding-left: 16px; padding-right: 16px; }
  .editor { grid-template-columns: 1fr; } .phone-wrap { display: none; }
  .filters, .grid2 { grid-template-columns: 1fr; } .grid4 { grid-template-columns: 1fr 1fr; }
  .rule { grid-template-columns: 1fr 1fr; } .rule .url { grid-column: 1 / -1; }
  .card.pad { padding: 20px; } .table-wrap { overflow-x: auto; }
}
