:root {
  --bg: #f2f0eb;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #202522;
  --muted: #6d726e;
  --line: #d9d5cc;
  --line-strong: #bdb8ad;
  --sidebar: #232a2e;
  --sidebar-deep: #1a2023;
  --sidebar-text: #c9cecb;
  --accent: #2f5f54;
  --accent-dark: #244b43;
  --accent-soft: #e5eeeb;
  --danger: #943a32;
  --danger-soft: #f6e7e4;
  --warn: #83631d;
  --warn-soft: #f7f0dc;
  --ok: #356346;
  --ok-soft: #e5efe7;
  --radius: 3px;
  --shadow: 0 1px 2px rgba(32, 37, 34, 0.06);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-family: var(--serif); font-size: 30px; font-weight: 500; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12px; }
pre { white-space: pre-wrap; word-break: break-word; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 244px;
  flex: 0 0 244px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 20px 18px 18px;
  border-bottom: 1px solid #323b40;
  color: #fff;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px;
  height: 38px;
  border: 1px solid #6f7f79;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #dfe9e4;
  flex: 0 0 38px;
}
.brand-text strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.25; }
.brand-text span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; color: #93a09a; margin-top: 3px; }
.nav { padding: 14px 10px 20px; overflow-y: auto; flex: 1; }
.nav-group { margin-bottom: 18px; }
.nav-label {
  padding: 0 10px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #89958f;
}
.nav a {
  display: block;
  padding: 7px 10px;
  color: var(--sidebar-text);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.nav a:hover { background: #2a3236; color: #fff; text-decoration: none; }
.nav a.active { background: #2b3438; border-left-color: #9ec5b5; color: #fff; }
.sidebar-foot {
  border-top: 1px solid #323b40;
  padding: 14px 16px;
  font-size: 12px;
  background: var(--sidebar-deep);
}
.sidebar-user { color: #dfe5e1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.sidebar-role { color: #8f9b95; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }
.sidebar-actions { display: flex; gap: 10px; margin-top: 10px; }
.sidebar-actions a, .sidebar-actions button {
  background: none; border: 0; padding: 0; color: #b9c4be; font-size: 12px; cursor: pointer; font-family: inherit;
}
.sidebar-actions a:hover, .sidebar-actions button:hover { color: #fff; text-decoration: underline; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 48px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  font-size: 12px;
  color: var(--muted);
}
.topbar-left { display: flex; gap: 10px; align-items: center; }
.topbar .sep { color: var(--line-strong); }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); color: var(--ink); padding: 4px 9px; cursor: pointer; }
.content { padding: 26px 30px 60px; max-width: 1280px; width: 100%; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.page-head p { color: var(--muted); font-size: 13px; margin-top: 6px; max-width: 720px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Cards and tables */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.card-header h2 { font-size: 14px; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.nobreak { white-space: nowrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.stat-value { font-family: var(--serif); font-size: 28px; line-height: 1.2; margin-top: 5px; }
.stat-note { font-size: 11px; color: var(--muted); margin-top: 3px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
tbody tr:hover { background: #fbfaf8; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.table-empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.row-title { font-weight: 600; color: var(--ink); }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Forms */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: #353a36; }
label .req { color: var(--danger); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  border-radius: 2px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #b9d2c8;
  outline-offset: 0;
  border-color: var(--accent);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
textarea.large { min-height: 220px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; font-size: 13px; }
.check input { margin-top: 3px; }
.check label { font-weight: 400; margin: 0; font-size: 13px; }
.form-actions { display: flex; gap: 8px; align-items: center; padding-top: 6px; flex-wrap: wrap; }
.center-actions { justify-content: center; }
fieldset { border: 1px solid var(--line); padding: 14px; margin: 0 0 16px; border-radius: var(--radius); }
legend { padding: 0 6px; font-size: 12px; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  padding: 7px 13px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.3;
  cursor: pointer;
  border-radius: 2px;
  text-align: center;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: #fff; border-color: #c9a49f; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-link { border: 0; background: none; padding: 0; color: var(--accent-dark); cursor: pointer; font: inherit; }
.btn-link:hover { text-decoration: underline; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Alerts and badges */
.alert { border: 1px solid; border-radius: var(--radius); padding: 11px 14px; margin-bottom: 18px; font-size: 13px; }
.alert-success { background: var(--ok-soft); border-color: #b7cfbd; color: #244a32; }
.alert-error { background: var(--danger-soft); border-color: #d6b0ab; color: #6f2c26; }
.alert-warn { background: var(--warn-soft); border-color: #ddc98f; color: #624a16; }
.alert-info { background: #eef1f4; border-color: #c9d0d6; color: #36434d; }
.badge {
  display: inline-block;
  padding: 2px 7px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid;
  border-radius: 2px;
  white-space: nowrap;
  font-weight: 600;
}
.badge-new { background: #eef1f4; border-color: #c5cfd7; color: #334552; }
.badge-progress { background: var(--warn-soft); border-color: #dcc58a; color: #6a4f15; }
.badge-waiting { background: #eaf0f6; border-color: #b9cadb; color: #2e4c68; }
.badge-closed, .badge-sent, .badge-ok { background: var(--ok-soft); border-color: #b7cfbd; color: #295039; }
.badge-failed, .badge-danger { background: var(--danger-soft); border-color: #d6b0ab; color: #75302a; }
.badge-draft { background: #f1f0ec; border-color: #d2cec4; color: #5b5f5b; }
.badge-queued, .badge-sending { background: var(--warn-soft); border-color: #dcc58a; color: #6a4f15; }
.badge-cancelled { background: #efeeea; border-color: #d0ccc2; color: #666; }

/* Dashboard */
.setup-list { list-style: none; margin: 0; padding: 0; }
.setup-list li { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.setup-list li:last-child { border-bottom: 0; }
.setup-mark { width: 16px; height: 16px; border: 1px solid var(--line-strong); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: transparent; flex: 0 0 16px; }
.setup-mark.done { background: var(--ok-soft); border-color: #9dbfa5; color: var(--ok); }
.bar-list { margin: 0; padding: 0; list-style: none; }
.bar-list li { display: grid; grid-template-columns: 160px 1fr 42px; gap: 10px; align-items: center; padding: 5px 0; font-size: 12px; }
.bar { height: 7px; background: #eceae5; border: 1px solid #dedbd4; }
.bar span { display: block; height: 100%; background: #9dbdb0; }
.day-note { font-size: 11px; color: var(--muted); }

/* Filters */
.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }
.filters .field.grow { flex: 1; min-width: 220px; }
.filters .btn { margin-bottom: 0; }

/* Misc */
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list-clean li:last-child { border-bottom: 0; }
.actions-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }
.pagination { display: flex; gap: 6px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); justify-content: space-between; font-size: 12px; color: var(--muted); }
.pagination-links { display: flex; gap: 5px; }
.pagination-links a, .pagination-links span { border: 1px solid var(--line); padding: 3px 8px; background: #fff; }
.pagination-links .current { background: var(--accent); color: #fff; border-color: var(--accent); }
.danger-zone { border-color: #d6b0ab; }
.danger-zone .card-header { background: var(--danger-soft); border-color: #d6b0ab; color: #6f2c26; }
.message { border-left: 2px solid var(--line-strong); padding: 2px 0 2px 12px; margin-bottom: 12px; }
.message.out { border-left-color: var(--accent); }
.message-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.message-text { white-space: pre-wrap; font-size: 13px; }
.preview-box { background: var(--surface-2); border: 1px solid var(--line); padding: 14px; white-space: pre-wrap; font-size: 13px; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.divider { border-top: 1px solid var(--line); margin: 16px 0; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.w-100 { width: 100%; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ml-auto { margin-left: auto; }
.w-0 { width: 0; }
.w-10 { width: 10%; }
.w-20 { width: 20%; }
.w-30 { width: 30%; }
.w-40 { width: 40%; }
.w-50 { width: 50%; }
.w-60 { width: 60%; }
.w-70 { width: 70%; }
.w-80 { width: 80%; }
.w-90 { width: 90%; }
.w-100 { width: 100%; }

/* Auth */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 42px 20px 60px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; color: var(--ink); }
.auth-brand:hover { text-decoration: none; }
.auth-brand .brand-mark { border-color: var(--accent); color: var(--accent-dark); }
.auth-brand strong { display: block; font-family: var(--serif); font-weight: 500; font-size: 18px; line-height: 1.2; }
.auth-brand span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); margin-top: 2px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); width: 100%; max-width: 430px; padding: 26px; }
.auth-card.wide { max-width: 820px; }
.auth-card h1 { font-size: 26px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.auth-foot { margin-top: 18px; font-size: 11px; color: var(--muted); text-align: center; max-width: 520px; }
.setup-section { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 20px; }
.setup-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.setup-section h2 { font-family: var(--serif); font-size: 19px; font-weight: 500; margin-bottom: 3px; }
.setup-section .section-note { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.setup-num { display: inline-block; width: 22px; height: 22px; border: 1px solid var(--line-strong); text-align: center; line-height: 20px; font-size: 11px; margin-right: 7px; color: var(--muted); }

/* Responsive */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.15s ease; }
  body.nav-open .sidebar { transform: translateX(0); }
  .menu-toggle { display: inline-block; }
  .content { padding: 20px 16px 50px; }
  .topbar { padding: 0 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 6px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 20px; }
  .filters .field, .filters .field.grow { min-width: 100%; }
  .bar-list li { grid-template-columns: 110px 1fr 36px; }
}
