:root {
  --brand: #2b74c7;
  --brand-dark: #1f5a9e;
  --brand-light: #c3d7f9;
  --brand-soft: #e8f1fb;
  --ink: #111827;
  --muted: #52565c;
  --bg: #f6f8fc;
  --card: #ffffff;
  --line: #e5e7eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 8px 24px rgba(17, 24, 39, .04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-size: 16px;
}

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

.wrap { width: min(1100px, calc(100% - 32px)); margin-inline: auto; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
}
.brand img { display: block; height: 30px; width: auto; }
.nav { display: flex; gap: 18px; margin-left: 12px; }
.nav a { color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--brand); border-bottom-color: var(--brand); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--muted); }
.lang-form { display: flex; align-items: center; gap: 4px; }

.main { padding: 32px 0 56px; min-height: calc(100vh - 140px); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 2px 0 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--brand); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.break { word-break: break-all; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 18px; }
.pack-card { border-top: 4px solid var(--brand); }
.pack-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.pack-head h2 { margin: 4px 0 2px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0 12px; }
.stats-small { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.stat-value { display: block; font-size: 24px; margin-top: 4px; letter-spacing: -.02em; }
.stat-strong { background: var(--brand-soft); border-color: var(--brand-light); }
.stat-strong .stat-value { color: var(--brand-dark); }

.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.progress { flex: 1; height: 10px; accent-color: var(--brand); }
.warnings { margin: 10px 0 0; padding-left: 18px; color: var(--warn); font-size: 13px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .02em; background: var(--brand-soft); color: var(--brand-dark); white-space: nowrap; }
.badge-open, .badge-ok { background: #e8f1fb; color: #1f5a9e; }
.badge-in_progress { background: #e0f2fe; color: #075985; }
.badge-waiting { background: #fef3c7; color: #92400e; }
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-closed { background: #f3f4f6; color: #374151; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-expired { background: #f3f4f6; color: #4b5563; }
.badge-overage { background: #fee2e2; color: #991b1b; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none;
  background: var(--brand); color: #fff; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; color: var(--brand-dark); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); border-color: var(--brand-light); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font: inherit; background: #fff; color: var(--ink);
}
.input:focus { outline: 2px solid var(--brand-light); border-color: var(--brand); }
.textarea { resize: vertical; min-height: 110px; }
.select { appearance: auto; }
.select-small { width: auto; padding: 6px 8px; font-size: 12px; border-radius: 8px; }
.stack > * + * { margin-top: 4px; }

.alert { border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-size: 14px; border: 1px solid var(--line); }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-info { background: var(--brand-soft); border-color: var(--brand-light); color: var(--brand-dark); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.ticket-list { list-style: none; margin: 0; padding: 0; }
.ticket-list li + li { border-top: 1px solid var(--line); }
.ticket-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 12px 2px; color: var(--ink); }
.ticket-row:hover { text-decoration: none; background: var(--bg); }
.ticket-ref { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--brand-dark); white-space: nowrap; }
.ticket-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-date { white-space: nowrap; }
.ticket-list-full .ticket-row { grid-template-columns: auto 1fr auto auto auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }

.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.activity-list li:last-child { border-bottom: 0; }
.activity-list a { display: flex; gap: 8px; color: var(--ink); min-width: 0; }
.activity-list a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.conversation { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.message { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.message-mine { background: var(--brand-soft); border-color: var(--brand-light); }
.message-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 13px; }
.message-body { white-space: pre-wrap; }
.attachments { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 18px; }
.step-indicator { flex: 1; padding: 8px 10px; border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.step-indicator.active { background: var(--brand); color: #fff; }
.wizard fieldset { border: 0; padding: 0; margin: 0; }
.wizard legend { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.js-steps .step:not(.active) { display: none; }
.step-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; font-weight: 600; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice input { accent-color: var(--brand); }
.summary-box { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }

.table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); }
.table tfoot th { background: var(--bg); }
.table .right { text-align: right; }

.pager { display: flex; gap: 8px; justify-content: space-between; margin-top: 8px; }
.period-list { list-style: none; margin: 0; padding: 0; }
.period-list li + li { border-top: 1px solid var(--line); }
.period-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 2px; color: var(--ink); }
.period-label { font-weight: 800; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.empty-state { text-align: center; padding: 40px 22px; }
.empty-state h1, .empty-state h2 { margin-top: 0; }

.auth-card { max-width: 520px; margin: 40px auto; }
.auth-head h1 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -.02em; }

.footer { border-top: 1px solid var(--line); background: var(--card); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; padding: 18px 0; color: var(--muted); font-size: 13px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; padding: 10px 0; }
  .nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .userbox { gap: 8px; }
  .user-name { display: none; }
  .stats, .stats-small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .ticket-row, .ticket-list-full .ticket-row { grid-template-columns: 1fr auto; }
  .ticket-subject { grid-column: 1 / -1; white-space: normal; }
  .ticket-date { display: none; }
  .choice-grid { grid-template-columns: 1fr; }
  .steps { flex-direction: column; }
}

@media (max-width: 520px) {
  .wrap { width: calc(100% - 24px); }
  .card { padding: 16px; }
  .stat-value { font-size: 20px; }
  .page-head { align-items: stretch; }
  .page-head .btn { width: 100%; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
}
