:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #20242c;
  --muted: #687083;
  --line: #dde2ea;
  --brand: #176b87;
  --brand-strong: #0f4f66;
  --accent: #d95f43;
  --ok: #2d8a5d;
  --warn: #b7791f;
  --danger: #c24141;
  --shadow: 0 8px 26px rgba(30, 42, 62, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.auth-shell { width: min(420px, 92vw); }
.auth-panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.auth-panel { padding: 28px; }
.brand { font-weight: 800; font-size: 18px; margin-bottom: 18px; color: var(--brand-strong); }

.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.customer-shell { min-height: 100vh; }
.sidebar {
  background: #12232d;
  color: white;
  padding: 24px;
}
.sidebar .brand { color: white; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar a {
  color: #dbe8ee;
  padding: 10px 12px;
  border-radius: 6px;
}
.sidebar a:hover { background: rgba(255,255,255,.08); }
.main-column { min-width: 0; }
.topbar {
  min-height: 64px;
  background: white;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.topbar-actions, .button-row, .language-switcher { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.content { padding: 24px; max-width: 1280px; margin: 0 auto; }
.customer-shell .content { max-width: 920px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.customer-hero {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}
.muted { color: var(--muted); font-size: 14px; }
.stack { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { padding: 20px; margin-bottom: 18px; }
.form-card { display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid #ccd3df;
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  background: white;
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.button {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 6px;
  padding: 9px 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.button.ghost { background: transparent; }
.button.large { padding: 14px 18px; font-size: 18px; }
.button.small { padding: 6px 9px; font-size: 13px; }
.button:disabled { opacity: .55; cursor: wait; }
.flash {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
}
.flash.success { background: #edf8f2; border-color: #b8e0cb; }
.flash.error { background: #fff1f0; border-color: #f0beb9; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.stat span { color: var(--muted); display: block; }
.stat strong { font-size: 28px; }
.ticket-cards { display: grid; gap: 12px; }
.ticket-card {
  display: grid;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--text);
}
.ticket-card-top { display: flex; justify-content: space-between; gap: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #384152;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status-new { background: #e8f1ff; color: #2357a4; }
.status-checking { background: #fff6dc; color: #95640d; }
.status-waiting_customer { background: #fff0e8; color: #ad4b1b; }
.status-in_progress { background: #e7f7ef; color: #1d754b; }
.status-done { background: #e9f9fb; color: #0b6b78; }
.status-closed { background: #eceff4; color: #596273; }
.priority-urgent { background: #ffe8e7; color: var(--danger); }
.priority-high { background: #fff1df; color: #a85518; }
.priority-normal { background: #edf4ff; color: #2f5d9a; }
.priority-low { background: #eef6f0; color: #2d744a; }
.badge.ok { background: #e8f7ef; color: var(--ok); }
.badge.warn { background: #fff6de; color: var(--warn); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; min-width: 170px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 180px; }

.ticket-admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.timeline { display: grid; gap: 12px; }
.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}
.message.internal { border-color: #f1d694; background: #fff9e9; }
.message-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.attachment-list { display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-list a { border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #f9fafc; }
.ai-panel textarea { margin-top: 12px; }

.upload-zone {
  border: 1.5px dashed #9fb0c2;
  border-radius: 8px;
  padding: 16px;
  background: #fbfdff;
}
.upload-zone.dragging { border-color: var(--brand); background: #edf8fb; }
.upload-zone p { margin: 0 0 10px; color: var(--muted); }
.upload-preview { display: grid; gap: 6px; margin-top: 10px; }
.upload-item { border-radius: 6px; background: #eef3f8; padding: 6px 8px; font-size: 13px; }
.settings-list { display: grid; gap: 14px; }
.settings-list div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ticket-admin-grid, .grid.two, .stats-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .content { padding: 14px; }
  .topbar, .page-head { align-items: flex-start; flex-direction: column; }
  .filter-bar input, .filter-bar select { width: 100%; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input { width: 100%; }
}
