:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #68736d;
  --paper: #f4f5f1;
  --panel: #ffffff;
  --line: #dde2dc;
  --green: #167653;
  --green-dark: #0d533a;
  --green-soft: #e7f4ed;
  --orange: #c96824;
  --red: #b33c35;
  --red-soft: #fdeceb;
  --shadow: 0 16px 40px rgba(21, 37, 29, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
body { font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell { display: flex; min-height: 100vh; }
.sidebar { width: 210px; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; padding: 20px 16px; background: #13231c; color: #dce8e1; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; margin: 0 6px 25px; }
.brand-mark, .auth-logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #d6f5e5; color: var(--green-dark); font-weight: 850; letter-spacing: -.04em; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a { padding: 9px 11px; border-radius: 8px; color: #b9c9c0; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: white; }
.sidebar-footer { margin-top: auto; padding: 18px 10px 0; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 3px; }
.sidebar-footer small { color: #8fa59a; text-transform: capitalize; }
.link-button { border: 0; padding: 8px 0 0; background: transparent; color: #b8d7c6; text-align: left; }
.main { width: calc(100% - 210px); margin-left: 210px; padding: 28px clamp(24px, 3vw, 46px) 52px; }
.main-auth { margin: 0; width: 100%; display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #ddf4e7, transparent 40%), var(--paper); }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-header h1 { font-family: Georgia, serif; font-size: clamp(28px, 3vw, 38px); line-height: 1.08; letter-spacing: -.03em; margin: 4px 0 9px; }
.page-header p { color: var(--muted); margin: 0; max-width: 680px; }
.eyebrow { color: var(--green); font-size: 12px; letter-spacing: .13em; text-transform: uppercase; font-weight: 800; margin: 0 0 5px; }
.muted { color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 17px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 4px; font-size: 27px; font-family: Georgia, serif; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.two-column-wide { grid-template-columns: .8fr 1.2fr; margin-bottom: 22px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 17px; overflow: hidden; }
.panel h2 { margin: 2px 0 0; font-size: 18px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.panel-header > a { color: var(--green); font-size: 13px; font-weight: 700; }
.panel-form { display: flex; align-items: center; justify-content: space-between; gap: 30px; }
.panel-form p { margin: 5px 0 0; }

.list { display: grid; }
.list-row { min-width: 0; display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.grow { min-width: 0; flex: 1; display: grid; gap: 3px; }
.grow small, td small, .script-meta, .timeline-row small { color: var(--muted); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #e7ece8; font-weight: 800; }
.device-icon { display: grid; place-items: center; width: 38px; height: 38px; background: #edf1ed; border-radius: 10px; }
.timeline { display: grid; }
.timeline-row { display: flex; gap: 12px; padding: 10px 0; }
.timeline-row div { display: grid; gap: 3px; }
.timeline-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-weight: 750; padding: 9px 13px; white-space: nowrap; }
.button:hover { border-color: #a8b3ac; }
.button-primary { background: var(--green); color: white; border-color: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-success { background: var(--green-soft); color: var(--green-dark); border-color: #b8dfca; }
.button-danger { background: var(--red-soft); color: var(--red); border-color: #f0c8c5; }
.button-small { padding: 7px 10px; font-size: 12px; }
.button-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.icon-button { border: 0; background: transparent; color: var(--red); font-size: 12px; font-weight: 700; }

.stack-form { display: grid; gap: 15px; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
label { display: grid; gap: 7px; color: #3e4943; font-size: 13px; font-weight: 700; }
label small { font-weight: 500; color: var(--muted); }
input, select, textarea { width: 100%; border: 1px solid #ccd4ce; border-radius: 8px; background: #fff; color: var(--ink); padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,118,83,.12); }
textarea { resize: vertical; line-height: 1.45; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; grid-template-columns: none; flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.phone-field { display: flex; align-items: center; border: 1px solid #ccd4ce; border-radius: 9px; background: #fff; overflow: hidden; }
.phone-field span { padding: 0 0 0 12px; color: var(--muted); }
.phone-field input { border: 0; box-shadow: none; }
.code-small, .code-editor, code { font-family: "Cascadia Code", Consolas, monospace; }
.code-editor { min-height: 310px; background: #13231c; color: #e6f4eb; border-color: #13231c; tab-size: 2; font-size: 12px; }

.auth-card { width: min(380px, calc(100vw - 32px)); background: #fff; padding: 28px; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 55px rgba(21,37,29,.11); }
.auth-card h1 { margin: 8px 0; font-family: Georgia, serif; font-size: 28px; letter-spacing: -.025em; }
.auth-card .stack-form { margin-top: 25px; }
.auth-logo { margin-bottom: 25px; }
.otp-input { text-align: center; font-size: 25px; letter-spacing: .35em; padding-left: calc(12px + .35em); }
.back-link { display: inline-block; margin-top: 17px; color: var(--green); font-weight: 700; font-size: 13px; }

.badge { display: inline-flex; align-items: center; width: fit-content; padding: 5px 8px; border-radius: 999px; background: #edf0ed; color: #536059; font-size: 11px; font-weight: 800; text-transform: capitalize; }
.badge-large { font-size: 13px; padding: 8px 12px; }
.badge-active, .badge-published { background: var(--green-soft); color: var(--green-dark); }
.badge-pending, .badge-invited { background: #fff1dc; color: #94501e; }
.badge-suspended, .badge-revoked { background: var(--red-soft); color: var(--red); }
.filter-row { display: flex; gap: 8px; margin: 0 0 15px; }
.chip { padding: 7px 11px; background: #fff; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip.active { background: var(--ink); color: white; border-color: var(--ink); }

.table-panel { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 13px 16px; text-align: left; color: var(--muted); background: #f9faf8; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td small { display: block; margin-top: 3px; max-width: 250px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:last-child td { border-bottom: 0; }
.clickable-row:hover { background: #fafbf9; }
.empty { color: var(--muted); text-align: center; padding: 28px !important; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.script-card { min-height: 170px; display: flex; flex-direction: column; padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
.script-card:hover { transform: translateY(-2px); border-color: #aebcb3; }
.script-card h2 { margin: 16px 0 7px; font-size: 18px; }
.script-card p { color: var(--muted); line-height: 1.5; margin: 0; }
.script-card-top { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #c6ccc8; }
.status-dot.on { background: #27a36e; box-shadow: 0 0 0 4px var(--green-soft); }
.script-meta { display: flex; gap: 10px; margin-top: auto; padding-top: 16px; font-size: 11px; }
.assignment-list { display: grid; }
.assignment-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.assignment-row:last-child { border-bottom: 0; }
.assignment-row select { width: 170px; }
.assignment-row .check { white-space: nowrap; }

.flash-stack { position: fixed; top: 18px; right: 22px; z-index: 20; display: grid; gap: 8px; width: min(420px, calc(100vw - 44px)); }
.flash { padding: 13px 15px; border-radius: 10px; box-shadow: var(--shadow); background: #fff; border: 1px solid var(--line); }
.flash-success { background: var(--green-soft); color: var(--green-dark); border-color: #b8dfca; }
.flash-error { background: var(--red-soft); color: var(--red); border-color: #f0c8c5; }

.publish-panel { max-width: 1080px; }
.publish-panel .button-primary { justify-self: start; }
.import-note { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--green-soft); color: var(--green-dark); font-size: 12px; }
.import-note span { color: #37634f; }
.advanced-panel { max-width: 1080px; padding: 0; }
.advanced-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; cursor: pointer; list-style: none; }
.advanced-panel summary::-webkit-details-marker { display: none; }
.advanced-panel summary > span:first-child { display: grid; gap: 3px; }
.advanced-panel summary small { color: var(--muted); font-weight: 400; }
.summary-action { color: var(--green); font-size: 12px; font-weight: 750; }
.advanced-panel[open] .summary-action { font-size: 0; }
.advanced-panel[open] .summary-action::after { content: "Close"; font-size: 12px; }
.advanced-form { padding: 0 18px 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.check-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }

@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-form, .assignment-row { align-items: stretch; flex-direction: column; }
  .assignment-row select { width: 100%; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 14px; padding: 12px 16px; overflow-x: auto; }
  .brand { margin: 0; white-space: nowrap; }
  .brand-mark { width: 34px; height: 34px; }
  .sidebar nav { display: flex; gap: 4px; }
  .sidebar nav a { padding: 8px 10px; white-space: nowrap; font-size: 12px; }
  .sidebar-footer { display: none; }
  .main { width: 100%; margin-left: 0; padding: 28px 18px 50px; }
  .main-auth { width: 100%; margin: 0; }
  .two-column, .two-column-wide, .card-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
}
