:root {
  --ink: #18313a;
  --muted: #6b7e86;
  --line: #dce7ea;
  --surface: #ffffff;
  --canvas: #f3f7f8;
  --brand: #0f5967;
  --brand-2: #168197;
  --brand-soft: #e7f4f6;
  --warning: #c56a18;
  --warning-soft: #fff2dc;
  --danger: #b63c45;
  --danger-soft: #fdebed;
  --success: #247a55;
  --success-soft: #e4f5ec;
  --info: #4269b1;
  --info-soft: #e9effb;
  --shadow: 0 14px 38px rgba(25, 59, 70, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); }
body { margin: 0; min-height: 100vh; background: var(--canvas); font-size: 16px; line-height: 1.45; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar { position: sticky; top: 0; z-index: 20; height: 68px; display: flex; align-items: center; gap: 30px; padding: 0 max(24px, calc((100vw - 1480px) / 2)); background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { width: 48px; height: 48px; display: inline-grid; place-items: center; border-radius: 15px; color: #fff; background: linear-gradient(145deg, var(--brand), var(--brand-2)); font-weight: 900; box-shadow: 0 8px 20px rgba(15,89,103,.2); }
.brand-mark.small { width: 34px; height: 34px; border-radius: 11px; font-size: 13px; }
.main-nav { display: flex; align-items: stretch; gap: 4px; height: 100%; }
.main-nav a { display: flex; align-items: center; padding: 0 14px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; }
.main-nav a:hover, .main-nav a.active { color: var(--brand); border-bottom-color: var(--brand-2); }
.logout-form { margin-left: auto; }
.link-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 10px; }
.link-button:hover { color: var(--danger); }

.page-shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 60px; }
.page-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 4px; color: var(--brand-2); font-size: 13px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: clamp(28px, 3.2vw, 42px); line-height: 1.1; }
h2 { font-size: 19px; }
.muted { color: var(--muted); }

.rate-strip { display: flex; gap: 1px; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: var(--line); box-shadow: var(--shadow); }
.rate-strip span { min-width: 120px; display: flex; flex-direction: column; padding: 10px 16px; background: #fff; }
.rate-strip small { color: var(--muted); font-size: 12px; }
.rate-strip strong { font-size: 15px; }
.sync-state { display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-size: 14px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.good { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }

.data-note { margin: -7px 0 17px; padding: 11px 14px; border: 1px solid #cfe0e4; border-radius: 12px; background: #f8fcfc; color: var(--muted); font-size: 14px; }
.data-note strong { color: var(--ink); }
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { position: relative; min-height: 132px; display: flex; flex-direction: column; padding: 19px 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); text-decoration: none; box-shadow: 0 8px 28px rgba(25,59,70,.045); transition: transform .15s ease, border-color .15s ease; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; right: -22px; bottom: -34px; width: 110px; height: 110px; border-radius: 50%; background: var(--brand-soft); opacity: .7; }
.stat-card:hover { transform: translateY(-2px); border-color: #9fc8d0; }
.stat-card.selected { border-color: var(--brand-2); box-shadow: 0 0 0 2px rgba(22,129,151,.13), var(--shadow); }
.stat-card span { color: var(--muted); font-size: 14px; font-weight: 700; }
.stat-card strong { position: relative; z-index: 1; margin: 6px 0 1px; font-size: 36px; line-height: 1; }
.stat-card small { color: var(--muted); }
.stat-card.urgent::after { background: var(--warning-soft); }
.stat-card.urgent strong { color: var(--warning); }
.stat-card.success-card::after { background: var(--success-soft); }
.stat-card.success-card strong { color: var(--success); }
.stat-card.danger-card::after { background: var(--danger-soft); }
.stat-card.danger-card strong { color: var(--danger); }

.panel { border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { min-height: 65px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-heading span { color: var(--muted); font-size: 13px; }
.table-heading > div { display: flex; align-items: baseline; gap: 10px; }
.search-box { width: min(340px, 45%); display: flex; align-items: center; gap: 10px; }
.search-box span { font-weight: 700; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #cbdcdf; border-radius: 11px; background: #fff; color: var(--ink); padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(22,129,151,.12); }
.search-box input { min-height: 39px; padding: 8px 11px; }

.table-wrap { overflow-x: auto; }
.clients-table { width: 100%; border-collapse: collapse; min-width: 1120px; }
.clients-table th { padding: 12px 14px; background: #f7fafb; color: var(--muted); font-size: 12px; text-align: left; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
.clients-table td { padding: 14px; vertical-align: middle; border-bottom: 1px solid #e8eff1; }
.clients-table tbody tr:hover { background: #f9fcfc; }
.clients-table tbody tr:last-child td { border-bottom: 0; }
.clients-table td small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.client-name { color: var(--ink); font-weight: 800; text-decoration: none; }
.client-name:hover { color: var(--brand-2); text-decoration: underline; }
.center { text-align: center; }
.actions-cell { width: 250px; }
.actions-cell, .message-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.actions-cell form, .message-actions form { margin: 0; }

.badge { display: inline-flex; align-items: center; min-height: 27px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.warning { background: var(--warning-soft); color: #945010; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: #edf2f3; color: #62747b; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border: 1px solid transparent; border-radius: 11px; text-decoration: none; font-weight: 800; cursor: pointer; transition: filter .15s ease, transform .15s ease; }
.button:hover { filter: brightness(.97); transform: translateY(-1px); }
.button.primary { background: var(--brand); color: #fff; }
.button.secondary { border-color: #bcd2d7; background: #f5fafb; color: var(--brand); }
.button.ghost { background: transparent; color: var(--muted); }
.button.mini { min-height: 33px; padding: 6px 9px; border-radius: 9px; font-size: 12px; }
.button.wide { width: 100%; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--brand); cursor: pointer; font-size: 18px; }

.alert { margin-bottom: 18px; padding: 13px 16px; border-radius: 12px; transition: opacity .3s ease; }
.alert.success { background: var(--success-soft); color: var(--success); border: 1px solid #bee3cf; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #f2c8cd; }
.alert.fade { opacity: .35; }
.empty-state { padding: 32px 20px; color: var(--muted); text-align: center; }

.install-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(circle at top left, #e2f1f4, transparent 38%), var(--canvas); }
.install-card, .login-card { width: min(720px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 23px; background: #fff; box-shadow: 0 24px 65px rgba(25,59,70,.14); }
.login-card { width: min(430px, 100%); }
.install-card h1, .login-card h1 { margin-top: 18px; }
.install-card > .muted, .login-card > .muted { margin-top: 6px; }
.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; color: #40545c; font-size: 14px; font-weight: 750; }
.settings-layout { display: grid; gap: 18px; }
.settings-layout .panel { padding-bottom: 20px; }
.settings-layout .form-grid { padding: 20px; }
.tariff-list { display: grid; padding: 8px 20px; }
.tariff-list label { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid #e8eff1; }
.tariff-list label:last-child { border-bottom: 0; }
.price-input { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.price-input input { width: 120px; text-align: right; }
.form-actions { display: flex; justify-content: flex-end; }

.back-link { display: inline-flex; margin-bottom: 15px; color: var(--brand); text-decoration: none; font-weight: 800; }
.client-hero { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 18px; padding: 25px 28px; border-radius: 20px; color: #fff; background: linear-gradient(125deg, #103f4a 0%, #0f6575 62%, #168197 100%); box-shadow: 0 18px 44px rgba(15,89,103,.21); }
.hero-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.hero-tags span { padding: 5px 10px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; background: rgba(255,255,255,.09); font-size: 13px; }
.hero-total { min-width: 210px; display: flex; flex-direction: column; text-align: right; }
.hero-total span, .hero-total small { color: rgba(255,255,255,.72); }
.hero-total strong { font-size: 34px; letter-spacing: -.04em; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(310px, .7fr); gap: 18px; }
.message-panel { min-height: 485px; display: flex; flex-direction: column; }
.message-text { flex: 1; min-height: 330px; resize: vertical; margin: 18px; width: calc(100% - 36px); line-height: 1.6; background: #f8fbfb; }
.message-actions { padding: 0 18px 18px; }
.side-stack { display: grid; align-content: start; gap: 18px; }
.panel.compact { padding-bottom: 18px; }
.panel.compact .form-stack { padding: 18px; }
.accent-panel { border-color: #a9ccd3; background: linear-gradient(180deg, #fff, #f1f9fa); }
.history-panel { margin-top: 18px; }
.renewal-list { display: grid; gap: 0; }
.renewal-card { padding: 20px; border-bottom: 1px solid var(--line); }
.renewal-card:last-child { border-bottom: 0; }
.renewal-card p { padding: 15px; border-radius: 12px; background: #f7fafb; color: #40545c; }
.renewal-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.renewal-summary span { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 50; transform: translate(-50%, 18px); padding: 11px 16px; border-radius: 11px; background: #173d46; color: #fff; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1000px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.three { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .topbar { height: auto; min-height: 62px; padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .brand > span:last-child { display: none; }
  .main-nav { order: 3; width: 100%; height: 42px; overflow-x: auto; }
  .main-nav a { white-space: nowrap; padding: 0 10px; }
  .page-shell { width: min(100% - 24px, 1480px); padding-top: 22px; }
  .page-title-row { align-items: stretch; flex-direction: column; }
  .rate-strip { width: 100%; }
  .rate-strip span { flex: 1; min-width: 0; padding: 9px; }
  .rate-strip strong { font-size: 13px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .stat-card { min-height: 115px; padding: 15px; }
  .stat-card strong { font-size: 30px; }
  .table-heading { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .install-card, .login-card { padding: 24px; }
  .client-hero { align-items: flex-start; flex-direction: column; padding: 22px; }
  .hero-total { text-align: left; }
  .side-stack { grid-template-columns: 1fr; }
  .message-actions { align-items: stretch; flex-direction: column; }
  .message-actions > *, .message-actions form, .message-actions form button { width: 100%; }
  .renewal-summary { align-items: flex-start; flex-direction: column; }
}
