/* Токены и базовая вёрстка — из сайта-сонника (sleep-site/static/css/style.css) */
:root { --radius: 14px; }

:root,
:root[data-theme="dark"] {
  --bg: #14151f;
  --surface: #1c1e2b;
  --surface-2: #242739;
  --text: #e7e9f5;
  --text-muted: #9498b0;
  --border: #2d3046;
  --primary: #7c8bfa;
  --primary-hover: #96a2ff;
  --accent: #b0a2f2;
  --good: #5fce8f;
  --warn: #e6b34f;
  --bad: #e8707f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #eef1fb;
  --text: #1f2436;
  --text-muted: #6b7086;
  --border: #dde1f0;
  --primary: #4f5fce;
  --primary-hover: #3d4bb0;
  --accent: #8b7fd6;
  --good: #3fa66b;
  --warn: #d99a2b;
  --bad: #d1495b;
  --shadow: 0 1px 3px rgba(31, 36, 54, 0.08), 0 1px 2px rgba(31, 36, 54, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; margin-right: 16px; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.topbar nav a.active,
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar .user-info {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { border-color: var(--primary); }
.theme-toggle-standalone { position: fixed; top: 14px; right: 14px; z-index: 30; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.container.narrow { max-width: 960px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

h1, h2, h3 { margin-top: 0; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }

.flash {
  background: var(--good);
  color: #1f2436;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.flash.error { background: var(--bad); color: #fff; }

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 14px;
}

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--primary); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 13px; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.toolbar > div { min-width: 140px; }
.toolbar > div.grow { flex: 1; min-width: 200px; }
.toolbar label { margin-top: 0; }
.toolbar .actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num { white-space: nowrap; text-align: right; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.user { background: var(--surface-2); color: var(--text-muted); }
.st-new { background: var(--primary); color: #fff; }
.st-in_work { background: var(--warn); color: #1f2436; }
.st-approved { background: var(--good); color: #1f2436; }
.st-rejected { background: var(--bad); color: #fff; }

.status-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.status-tabs a {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.status-tabs a.active { background: var(--surface-2); border-color: var(--primary); }
.status-tabs a:hover { text-decoration: none; border-color: var(--primary); }
.status-tabs .count { color: var(--text-muted); font-weight: 400; margin-left: 4px; }

dl.fields { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: 0; margin: 0; }
dl.fields dt, dl.fields dd { padding: 8px 0; border-bottom: 1px solid var(--border); margin: 0; }
dl.fields dt { color: var(--text-muted); font-size: 14px; padding-right: 12px; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.photo {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.photo img { display: block; width: 100%; height: 200px; object-fit: cover; }
.photo .cap { padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.photo .nofile { height: 200px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }

.side-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
@media (max-width: 860px) {
  .side-grid { grid-template-columns: 1fr; }
  dl.fields { grid-template-columns: 1fr; }
  dl.fields dt { border-bottom: none; padding-bottom: 0; }
}

code.inline { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* --- тест-стенд (чат) --- */
.sim-wrap { max-width: 520px; margin: 0 auto; }
.chat {
  height: 62vh;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  font-size: 14px;
}
.bubble.bot { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; }
.bubble.me { background: var(--primary); color: #fff; align-self: flex-end; }
.bubble.sys { align-self: center; background: transparent; color: var(--text-muted); font-size: 12px; }
.bubble.mgr { align-self: center; background: var(--warn); color: #1f2436; font-size: 13px; }
.bubble img { max-width: 180px; border-radius: 8px; display: block; }
.kb { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.kb .kb-row { display: flex; gap: 4px; }
.kb button {
  flex: 1;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.kb button:hover { background: var(--primary); color: #fff; }
.kb button:disabled { opacity: 0.4; cursor: default; background: transparent; color: var(--primary); }
.composer { display: flex; gap: 8px; margin-top: 10px; }
.composer input[type="text"] { flex: 1; }
.composer .attach { position: relative; overflow: hidden; }
.composer .attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

@media (max-width: 600px) {
  .container { padding: 16px 16px 40px; }
  .topbar { padding: 10px 16px; }
}

.topbar .brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-logo { width: 28px; height: 28px; display: block; }

/* --- главная --- */
.dash-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg a { padding: 5px 12px; border-radius: 8px; color: var(--text-muted); font-size: 13px; font-weight: 600; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.tile-label { font-size: 13px; color: var(--text-muted); }
.tile-value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--text-muted); }

.chart-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; margin-bottom: 12px; }
.daychart { position: relative; height: 160px; display: flex; align-items: flex-end; gap: 2px;
            border-bottom: 1px solid var(--border); }
.daychart .day { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; outline: none; }
.daychart .bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 0; transition: opacity .1s; }
.daychart .day.hover .bar, .daychart .day:focus .bar { background: var(--primary-hover); }
.daychart .day.hover { background: var(--surface-2); border-radius: 4px 4px 0 0; }
.daychart .tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--text); color: var(--bg);
                 font-size: 12px; padding: 5px 9px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.daychart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.table-view { margin-top: 12px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--text-muted); }
.table-view table { margin-top: 8px; }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-bottom: 0; }
.dash-grid .card { margin-bottom: 20px; }
.hbar { margin-bottom: 12px; }
.hbar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 5px; }
.hbar-top .num { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hbar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.status-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0;
              border-bottom: 1px solid var(--border); color: var(--text); }
.status-row:last-child { border-bottom: none; }
.status-row:hover { text-decoration: none; }
.status-row .num { font-weight: 600; font-variant-numeric: tabular-nums; }

.badge.form-short { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.badge.form-long { background: transparent; border: 1px solid var(--primary); color: var(--primary); }

@media (max-width: 700px) {
  .topbar { gap: 8px; }
  .topbar .brand { margin-right: auto; }
  .topbar nav { order: 3; flex: 0 0 100%; overflow-x: auto; flex-wrap: nowrap; }
  .topbar nav a { white-space: nowrap; }
  .hide-sm { display: none; }
  .latest td { padding-left: 6px; padding-right: 6px; }
}
