:root {
  --paper: #fafaf7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --hairline: #f1f5f9;
  --soft: #f8fafc;
  --white: #fff;
  --danger: #dc2626;
  --success: #059669;
  --warning: #b45309;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, rgba(99,102,241,0.06), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(15,23,42,0.04), transparent 50%),
    var(--paper);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.display { font-family: 'Cormorant Garamond', serif; letter-spacing: 0.005em; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-wrap { width: 100%; max-width: 448px; }
.login-header { text-align: center; margin-bottom: 40px; }
.logo-badge {
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  margin-bottom: 20px;
  box-shadow: 0 12px 28px -18px rgba(15,23,42,.8);
}
.login-header h1 { margin: 0; font-size: 52px; line-height: 1; font-weight: 600; }
.login-header p { margin: 10px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .025em; }

.card {
  background: var(--white);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(15,23,42,0.04), 0 30px 60px -30px rgba(15,23,42,0.18);
}

.login-card { padding: 32px; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  transition: all .2s;
}
.textarea { min-height: 112px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(15,23,42,0.06);
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font-weight: 600;
  letter-spacing: .025em;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #1e293b; transform: translateY(-1px); box-shadow: 0 8px 20px -8px rgba(15,23,42,0.4); }
.btn-soft { background: var(--soft); color: #475569; border: 1px solid var(--line); }
.btn-soft:hover { background: #f1f5f9; color: var(--ink); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: #64748b; padding: 9px 10px; }
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }
.btn-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fee2e2; }
.btn-danger:hover { background: #fee2e2; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.error-box {
  display: none;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #fee2e2;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}
.sidebar {
  border-right: 1px solid var(--hairline);
  padding: 26px 18px;
  background: rgba(255,255,255,.58);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand h1 { margin: 0; font-size: 36px; line-height: 1; font-weight: 600; }
.brand p { margin: 8px 0 26px; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.nav { display: grid; gap: 6px; }
.nav button {
  width: 100%;
  justify-content: flex-start;
  color: #475569;
  font-size: 14px;
}
.nav button.active { background: var(--ink); color: #fff; }
.sidebar-footer {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 20px;
  display: grid;
  gap: 10px;
}
.user-chip { font-size: 12px; color: var(--muted); line-height: 1.5; }

.main { padding: 28px; min-width: 0; }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0; font-size: 42px; line-height: 1; font-weight: 600; }
.topbar p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; }

.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.stat { padding: 18px; }
.stat .label { color: #94a3b8; }
.stat strong { display: block; margin-top: 8px; font-size: 30px; font-weight: 600; }

.panel { padding: 18px; }
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-title h3 { margin: 0; font-size: 15px; letter-spacing: .08em; text-transform: uppercase; color: #475569; }

.table-wrap { overflow: auto; border: 1px solid var(--hairline); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 860px; background: #fff; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--hairline); text-align: left; font-size: 13px; vertical-align: top; }
th { color: #64748b; background: var(--soft); font-size: 11px; text-transform: uppercase; letter-spacing: .09em; }
tr:hover td { background: #fafafa; }
.linkish { color: var(--ink); font-weight: 700; background: none; border: 0; padding: 0; text-align: left; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  border: 1px solid var(--line);
  background: var(--soft);
  color: #475569;
}
.priority-Critical { background: #fef2f2; color: #b91c1c; border-color: #fee2e2; }
.priority-High { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.priority-Medium { background: #f8fafc; color: #334155; }
.priority-Low { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.sla-breached { background: #fef2f2; color: #b91c1c; border-color: #fee2e2; }
.sla-ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }

.filters {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, minmax(140px, .5fr));
  gap: 10px;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) 360px;
  gap: 18px;
}
.ticket-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 16px;
  margin-bottom: 16px;
}
.ticket-header h3 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.thread { display: grid; gap: 0; }
.timeline-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  position: relative;
}
.timeline-rail {
  display: flex;
  align-items: stretch;
  flex-direction: column;
  padding-top: 12px;
}
.timeline-dot {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: #64748b;
  font-size: 12px;
}
.timeline-line {
  width: 1px;
  flex: 1;
  margin: 6px auto 6px;
  background: var(--line);
}
.timeline-item:last-of-type .timeline-line { background: transparent; }
.timeline-item.incoming .timeline-dot {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #334155;
}
.timeline-item.outgoing .timeline-dot {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}
.message, .note {
  border: 1px solid var(--hairline);
  background: var(--soft);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.message.incoming {
  background: #f8fafc;
  border-color: #dbe3ee;
  border-left: 4px solid #64748b;
}
.message.outgoing {
  background: #f0fdf4;
  border-color: #bbf7d0;
  border-left: 4px solid #059669;
}
.message-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.message-meta strong {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.step-time {
  display: inline-flex;
  margin-left: 10px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: #475569;
  font-weight: 700;
}
.message.outgoing .step-time {
  background: #dcfce7;
  border-color: #86efac;
  color: #047857;
}
.message.incoming .step-time {
  background: #fff;
  border-color: #cbd5e1;
  color: #334155;
}
.message-body { white-space: pre-wrap; line-height: 1.65; font-size: 14px; }
.quoted-mail {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: #64748b;
  font-size: 13px;
}
.quoted-mail summary {
  cursor: pointer;
  font-weight: 700;
  color: #475569;
}
.quoted-mail div { margin-top: 10px; white-space: pre-wrap; }
.attachment-flag {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 999px;
  padding: 5px 9px;
}
.note { background: #fffbeb; border-color: #fde68a; }
.warning { color: var(--warning); font-size: 12px; font-weight: 700; margin-bottom: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }
.section-space { margin-top: 16px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.24);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
.modal { width: min(760px, 100%); max-height: 90vh; overflow: auto; padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 28px; font-weight: 600; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-footer { position: static; margin-top: 18px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .main { padding: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar h2 { font-size: 34px; }
  .stats, .form-grid, .filters { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
}
