:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e4e7eb;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --sidebar-bg: #14161c;
  --sidebar-text: #c7cad1;
  --sidebar-text-active: #ffffff;
  --accent: #3b6cf6;
  --accent-hover: #2f57d0;
  --radius: 8px;

  --status-new: #3b6cf6;
  --status-open: #d97706;
  --status-pending: #7c3aed;
  --status-closed: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  padding: 0 20px 20px;
  letter-spacing: -0.02em;
}
.sidebar .brand span { color: var(--accent); font-weight: 400; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar nav a {
  color: var(--sidebar-text);
  padding: 10px 20px;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.04); }
.sidebar nav a.active {
  color: var(--sidebar-text-active);
  border-left-color: var(--accent);
  background: rgba(255,255,255,0.06);
  font-weight: 600;
}

.sidebar .logout-form { padding: 10px 20px 0; }
.sidebar .logout-form button {
  background: none; border: 1px solid #3a3d47; color: var(--sidebar-text);
  padding: 8px 12px; border-radius: var(--radius); cursor: pointer; width: 100%; font-size: 13px;
}
.sidebar .logout-form button:hover { color: #fff; border-color: #666; }

.content { flex: 1; padding: 32px 40px; max-width: 1100px; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; }
.subtitle { color: var(--text-muted); font-size: 13px; margin: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
}

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--border);
}
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.ticket-row:hover { background: #fafbfc; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: #fff;
}
.badge-new { background: var(--status-new); }
.badge-open { background: var(--status-open); }
.badge-pending { background: var(--status-pending); }
.badge-closed { background: var(--status-closed); }

.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.filters a {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text);
  font-size: 13px;
}
.filters a.active { background: var(--text); color: #fff; border-color: var(--text); }
.filters a:hover { text-decoration: none; border-color: var(--text); }

form.inline { display: inline; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

button, .btn {
  display: inline-block; background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 6px; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button.secondary, .btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover, .btn.secondary:hover { background: #f3f4f6; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }

.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
.meta-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.meta-row:last-child { border-bottom: none; }
.meta-row .k { color: var(--text-muted); }

.message-list { display: flex; flex-direction: column; gap: 10px; }
.message {
  padding: 10px 14px; border-radius: 10px; max-width: 90%; font-size: 13.5px;
  border: 1px solid var(--border);
}
.message.client { background: #fff; align-self: flex-start; }
.message.manager { background: #eef2ff; align-self: flex-end; border-color: #dbe3fd; }
.message.unknown, .message.system { background: #f9fafb; align-self: flex-start; }
.message .meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.message .body { white-space: pre-wrap; word-break: break-word; }

.empty-state { color: var(--text-muted); padding: 40px 0; text-align: center; }

.stat-row { display: flex; gap: 16px; margin-bottom: 24px; }
.stat-card {
  flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .num { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.stat-card .label { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

.flash {
  padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px;
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;
}
.flash.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.login-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-box {
  width: 320px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px;
}
.login-box .brand { font-weight: 700; font-size: 20px; margin-bottom: 4px; }
.login-box .brand span { color: var(--accent); }
.login-box p.subtitle { margin-bottom: 20px; }
.login-box button { width: 100%; margin-top: 4px; }
.error-text { color: #dc2626; font-size: 13px; margin: -6px 0 14px; }
