:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1b2333;
  --muted: #6b7489;
  --border: #e3e7f0;
  --primary: #0070e0;
  --primary-dark: #003087;
  --ok: #0f8a4b;
  --ok-bg: #e3f6ec;
  --warning: #9a6200;
  --warning-bg: #fff3d6;
  --error: #c62828;
  --error-bg: #fdecec;
  --muted-bg: #eef0f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12.5px ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--muted-bg); padding: 1px 6px; border-radius: 6px; }
h1 { font-size: 26px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 16px; margin: 0; }
small, .muted { color: var(--muted); }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; padding: 22px 16px;
  background: linear-gradient(180deg, var(--primary-dark), #001c64);
  color: #fff; display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; color: inherit; opacity: .7; font-size: 12px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: #fff; color: var(--primary-dark); font-weight: 800; font-size: 20px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { color: rgba(255, 255, 255, .82); padding: 10px 12px; border-radius: 10px; font-weight: 500; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.sidebar nav a.active { background: rgba(255, 255, 255, .16); color: #fff; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.link-button { background: none; border: 0; color: rgba(255, 255, 255, .8); cursor: pointer; padding: 0; font: inherit; }
.link-button:hover { color: #fff; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 30px 34px 60px; display: flex; flex-direction: column; gap: 22px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.subtitle { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-accounts { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.account-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.account-card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.account-card dt { color: var(--muted); }
.account-card dd { margin: 0; text-align: right; }
.account-error { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--error-bg); color: var(--error); font-size: 13.5px; }
.account-row { display: flex; flex-direction: column; gap: 16px; }
.details { font-size: 14px; }
.details .label { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.empty-card { text-align: center; padding: 34px; }
.empty-card p { color: var(--muted); }
.empty { color: var(--muted); margin: 6px 0; }
.text-error { color: var(--error); font-weight: 600; }

.pill { display: inline-block; white-space: nowrap; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-error { background: var(--error-bg); color: var(--error); }
.pill-muted { background: var(--muted-bg); color: var(--muted); }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.button:hover { background: var(--muted-bg); text-decoration: none; }
.button-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button-primary:hover { background: #005bb8; }
.button-danger { color: var(--error); border-color: #f3c4c4; }
.button-danger:hover { background: var(--error-bg); }

.flash { padding: 12px 16px; border-radius: 10px; font-weight: 500; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-warning { background: var(--warning-bg); color: var(--warning); }
.flash-error { background: var(--error-bg); color: var(--error); }

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item small { display: block; }

.notification-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.telegram-message {
  margin: 12px 0 0; padding: 14px 16px; border-radius: 12px; background: #eaf3ff;
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; white-space: pre-wrap;
}

.form { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
input, select {
  font: inherit; font-weight: 400; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid rgba(0, 112, 224, .35); border-color: var(--primary); }
.hint { background: var(--muted-bg); border-radius: 10px; padding: 12px 14px; font-size: 13.5px; color: #3c4559; }

.login-wrapper { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--primary-dark), var(--primary)); }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.brand-center { justify-content: center; margin-bottom: 6px; }
.brand-center .brand-logo { background: var(--primary-dark); color: #fff; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--muted-bg); border-radius: 10px; padding: 10px 12px; }
.stat .label { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 19px; white-space: nowrap; }
.stat small { display: block; color: var(--muted); }
.stat-alert { background: var(--error-bg); color: var(--error); }
.stat-ok { background: var(--ok-bg); color: var(--ok); }
.gap-alert { border-left: 4px solid var(--error); background: var(--error-bg); border-radius: 10px; padding: 12px 14px; }
.gap-alert p { margin: 0 0 8px; font-weight: 600; }
.gap-alert ul { margin: 0 0 10px; padding-left: 18px; font-size: 14px; }
.gap-alert li { margin-bottom: 4px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.inline-form input[type=text] { min-width: 0; width: 160px; }
.inline-form .grow input { width: 100%; }
.inline-form .grow { flex: 1 1 200px; }
.check { flex-direction: row !important; align-items: center; gap: 6px !important; font-weight: 400 !important; }
.balance-row td { vertical-align: middle; }
.row-muted td { color: var(--muted); }
details.compact summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 14px 16px; gap: 12px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar nav a { white-space: nowrap; padding: 7px 10px; font-size: 14px; }
  .sidebar-footer { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; }
  .content { padding: 20px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
