:root {
  --ink: #17221c;
  --muted: #66736c;
  --paper: #f4f2e9;
  --card: #fffef8;
  --line: #dcdccf;
  --green: #176447;
  --green-dark: #0e4934;
  --lime: #c9f269;
  --amber: #eaa928;
  --red: #b94b3d;
  --shadow: 0 12px 40px rgba(30, 45, 36, .08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 4vw, 3.35rem); letter-spacing: -.055em; line-height: .95; }
h2 { margin-bottom: 0; font-size: 1.15rem; letter-spacing: -.02em; }

.topbar { height: 68px; padding: 0 clamp(18px, 4vw, 54px); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(244, 242, 233, .92); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 11px; font-weight: 750; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px 4px 14px 4px; display: grid; place-items: center; background: var(--green); color: white; font-weight: 900; letter-spacing: -.05em; }
.brand-mark.small { width: 35px; height: 35px; border-radius: 10px 3px 10px 3px; font-size: .78rem; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.refresh-state { font-size: .76rem; color: var(--muted); }

.app-shell { padding: 22px clamp(14px, 4vw, 54px) 60px; max-width: 1600px; margin: auto; }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); gap: 4px; scrollbar-width: none; }
.tab { border: 0; background: transparent; padding: 13px 18px; white-space: nowrap; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 650; color: var(--muted); }
.tab.active { color: var(--green); border-color: var(--green); }
.panel { display: none; padding-top: 34px; }
.panel.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 28px; }
.eyebrow { margin-bottom: 8px; color: var(--green); text-transform: uppercase; letter-spacing: .12em; font-size: .7rem; font-weight: 850; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .88rem; margin: -14px 0 20px; }

.button, .chip { border: 1px solid var(--line); border-radius: 9px; background: var(--card); padding: 10px 15px; cursor: pointer; font-weight: 700; transition: .15s ease; }
.button:hover, .chip:hover { border-color: var(--green); transform: translateY(-1px); }
.button.primary { background: var(--green); border-color: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.ghost { background: transparent; }
.button.compact { padding: 8px 12px; }
.button.danger { color: var(--red); }
.chip { padding: 8px 12px; border-radius: 30px; font-size: .82rem; }
.chip.active { color: white; border-color: var(--green); background: var(--green); }
.period-controls { display: flex; flex-direction: column; align-items: end; gap: 10px; }
.preset-group, .date-range, .action-row { display: flex; align-items: center; gap: 8px; }
input { border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 9px 11px; color: var(--ink); min-width: 0; }
input:focus { outline: 3px solid rgba(23, 100, 71, .14); border-color: var(--green); }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.metric { min-height: 145px; border: 1px solid var(--line); background: var(--card); padding: 22px; display: flex; flex-direction: column; border-radius: 4px 18px 4px 18px; }
.metric.featured { color: white; background: var(--green); border-color: var(--green); }
.metric span { color: var(--muted); font-size: .82rem; font-weight: 700; }
.metric.featured span, .metric.featured small { color: #d7f4e8; }
.metric strong { font-size: clamp(2rem, 3vw, 3rem); letter-spacing: -.055em; margin: auto 0 3px; }
.metric small { color: var(--muted); }

.report-grid { display: grid; grid-template-columns: 1.65fr 1fr; gap: 14px; margin-bottom: 14px; }
.card { border: 1px solid var(--line); background: var(--card); border-radius: 4px 18px 4px 18px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { min-height: 62px; padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.card-head .muted { font-size: .75rem; }
.breakdown { display: grid; grid-template-columns: 1fr 1fr; }
.breakdown-row { padding: 16px 20px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; }
.breakdown-row:nth-child(odd) { border-right: 1px solid var(--line); }
.breakdown-row:nth-last-child(-n+2) { border-bottom: 0; }
.breakdown-row strong { font-size: .9rem; }
.breakdown-row span { color: var(--muted); font-size: .77rem; }
.breakdown-row b { grid-row: span 2; align-self: center; font-size: 1.05rem; }
.rank-list { min-height: 180px; }
.rank-row { padding: 14px 20px; display: grid; grid-template-columns: 27px 1fr auto; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: 0; }
.rank-number { color: var(--muted); font-size: .75rem; }
.rank-row small { display: block; color: var(--muted); margin-top: 3px; }
.empty-state { color: var(--muted); display: grid; place-items: center; }

.table-card { margin-top: 14px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th, td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); font-size: .82rem; vertical-align: top; }
th { color: var(--muted); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; background: #f9f8f1; }
tbody tr:last-child td { border-bottom: 0; }
td.number, th.number { text-align: right; }
.table-actions { display: flex; justify-content: end; gap: 6px; }
.table-actions .button { padding: 6px 9px; font-size: .76rem; }
.status { display: inline-flex; align-items: center; gap: 6px; border-radius: 20px; padding: 5px 9px; background: #e6eee9; color: var(--green); font-size: .72rem; font-weight: 750; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.offline, .status.rejected, .status.blocked { color: var(--red); background: #f8e8e4; }
.status.unknown { color: #806316; background: #f7edcf; }

.enrollment-card { background: var(--green); color: white; display: flex; align-items: center; justify-content: space-between; gap: 30px; padding: 28px; margin-bottom: 16px; border-radius: 4px 22px 4px 22px; }
.enrollment-card .eyebrow { color: var(--lime); }
.enrollment-card p { color: #d4e9df; }
.enrollment-card code { display: block; max-width: 650px; overflow-wrap: anywhere; font-size: .75rem; }
.enrollment-card img { background: white; padding: 10px; border-radius: 6px; }
.hidden { display: none !important; }
.application-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 32px; padding: 28px; margin-bottom: 16px; color: white; background: var(--green); border-radius: 4px 22px 4px 22px; box-shadow: var(--shadow); }
.application-copy { max-width: 760px; }
.application-copy .eyebrow { color: var(--lime); }
.application-copy h2 { font-size: clamp(1.5rem, 3vw, 2.35rem); margin-bottom: 12px; }
.application-copy p:not(.eyebrow) { color: #d4e9df; line-height: 1.55; }
.application-copy .button { text-decoration: none; background: var(--lime); border-color: var(--lime); color: var(--green-dark); }
.application-copy code { max-width: min(520px, 100%); overflow-wrap: anywhere; color: #d4e9df; font-size: .72rem; }
.application-qr { display: grid; justify-items: center; gap: 8px; color: #d4e9df; font-size: .72rem; }
.application-qr img { padding: 9px; background: white; border-radius: 6px; }
.device-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.device-card { padding: 22px; border: 1px solid var(--line); background: var(--card); border-radius: 4px 18px 4px 18px; }
.device-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.device-card dl { display: grid; grid-template-columns: 1fr auto; margin: 0; gap: 11px; font-size: .82rem; }
.device-card dt { color: var(--muted); }
.device-card dd { margin: 0; text-align: right; }

.notice { border-left: 4px solid var(--amber); background: #fff7df; padding: 14px 16px; margin: -8px 0 20px; font-size: .86rem; }
.tariff-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tariff-item { border: 1px solid var(--line); background: var(--card); padding: 18px; border-radius: 4px 14px 4px 14px; display: grid; grid-template-columns: 1fr 135px; gap: 12px; align-items: center; }
.tariff-item label { font-weight: 700; }
.money-input { display: flex; align-items: center; gap: 7px; }
.money-input input { width: 100%; text-align: right; }
.form-footer { margin-top: 16px; display: flex; justify-content: end; }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(380px, calc(100vw - 30px)); background: var(--ink); color: white; border-radius: 9px; padding: 13px 17px; box-shadow: var(--shadow); transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; z-index: 30; }
.toast.show { transform: none; opacity: 1; }
.toast.error { background: var(--red); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--green); background-image: radial-gradient(circle at 10% 10%, rgba(201, 242, 105, .24), transparent 35%), linear-gradient(140deg, transparent 65%, rgba(0, 0, 0, .12)); }
.login-card { width: min(430px, 100%); background: var(--card); padding: clamp(28px, 7vw, 48px); border-radius: 5px 28px 5px 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .22); }
.login-card .brand-mark { margin-bottom: 28px; }
.login-card h1 { font-size: 2.6rem; margin-bottom: 13px; }
.stack-form { display: grid; gap: 16px; margin-top: 26px; }
.stack-form label { display: grid; gap: 7px; font-size: .78rem; font-weight: 750; }
.stack-form input { padding: 12px; }
.alert { background: #f8e8e4; color: #8c3026; padding: 11px 13px; border-radius: 7px; margin-top: 18px; font-size: .84rem; }

@media (max-width: 1000px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .report-grid { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .topbar { padding: 0 15px; }
  .brand > span:last-child, .refresh-state { display: none; }
  .app-shell { padding: 8px 10px 36px; }
  .tabs { margin: 0 -10px; padding: 0 8px; }
  .tab { padding: 13px 12px; font-size: .84rem; }
  .panel { padding-top: 24px; }
  .section-head { align-items: stretch; flex-direction: column; gap: 20px; }
  .period-controls { align-items: stretch; }
  .preset-group { overflow-x: auto; }
  .date-range { flex-wrap: wrap; }
  .date-range input { flex: 1; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 125px; padding: 16px; }
  .metric strong { font-size: 2rem; }
  .breakdown { grid-template-columns: 1fr; }
  .breakdown-row:nth-child(odd) { border-right: 0; }
  .breakdown-row:nth-last-child(2) { border-bottom: 1px solid var(--line); }
  .device-grid, .tariff-grid { grid-template-columns: 1fr; }
  .enrollment-card { flex-direction: column; align-items: start; }
  .enrollment-card img { align-self: center; width: min(220px, 100%); height: auto; }
  .application-card { grid-template-columns: 1fr; }
  .application-card .action-row { align-items: start; flex-direction: column; }
  .application-qr { justify-self: center; }
  .application-qr img { width: min(190px, 100%); height: auto; }
  .action-row { flex-wrap: wrap; }
  .tariff-item { grid-template-columns: 1fr 120px; }
}

@media (max-width: 420px) {
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 112px; }
}
