:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warn: #d97706;
  --input-bg: #0b1424;
  --row-hover: rgba(255,255,255,.02);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: #60a5fa; }

button {
  font-family: inherit; font-size: 14px;
  padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  cursor: pointer; transition: background .15s;
}
button:hover { background: #334155; }
button.primary { background: var(--primary); border-color: var(--primary); }
button.primary:hover { background: var(--primary-hover); }
button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-hover); }
button.ghost { background: transparent; }

input, select, textarea {
  font-family: inherit; font-size: 14px;
  padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.login-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 700; font-size: 20px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: white;
}
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-error { color: #f87171; font-size: 13px; margin-top: 10px; min-height: 16px; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 20px 0; display: flex; flex-direction: column; }
.sidebar .brand { padding: 0 20px 20px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--text); cursor: pointer;
  border-left: 3px solid transparent; font-size: 14px;
}
.nav-link:hover { background: var(--panel-2); }
.nav-link.active { background: var(--panel-2); border-left-color: var(--primary); font-weight: 600; }
.nav-spacer { flex: 1; }
.userbar { padding: 16px 20px; border-top: 1px solid var(--border); font-size: 13px; }
.userbar .who { color: var(--muted); margin-bottom: 8px; word-break: break-all; }

.main { padding: 24px 32px; overflow-x: auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .actions { display: flex; gap: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .val { font-size: 26px; font-weight: 700; margin-top: 4px; }

.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: var(--panel-2); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--row-hover); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(22,163,74,.15); color: #4ade80; }
.badge.warn { background: rgba(217,119,6,.18); color: #fbbf24; }
.badge.crit { background: rgba(220,38,38,.18); color: #f87171; }
.badge.expired { background: rgba(100,116,139,.25); color: #cbd5e1; }
.badge.role { background: rgba(37,99,235,.18); color: #93c5fd; }
.badge.sent { background: rgba(22,163,74,.15); color: #4ade80; }
.badge.error { background: rgba(220,38,38,.18); color: #f87171; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 520px; padding: 24px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.acct-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.acct-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px; color: var(--text); cursor: pointer; transition: background .12s, border-color .12s; }
.acct-row:hover { border-color: var(--accent); background: var(--panel); }
.acct-row-label { flex: 1; }
.acct-row-title { font-size: 14px; font-weight: 600; }
.acct-row-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.acct-row-chev { color: var(--muted); font-size: 22px; line-height: 1; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

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

/* Ticket thread */
.ticket-thread { display: flex; flex-direction: column; gap: 10px; max-height: 380px; overflow-y: auto; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg); }
.ticket-msg { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); }
.ticket-msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.ticket-msg .body { font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.ticket-msg.orig    { border-left: 3px solid #94a3b8; }
.ticket-msg.client  { border-left: 3px solid #94a3b8; }
.ticket-msg.admin   { border-left: 3px solid #3b82f6; }
.ticket-msg.internal{ border-left: 3px solid #f59e0b; background: rgba(245,158,11,0.06); }

.row-click { cursor: pointer; }
.row-click:hover { background: var(--input-bg); }

/* Job terms acceptance box */
.terms-box { margin: 12px 0; padding: 14px 16px; border: 2px solid var(--accent); border-radius: 8px; background: rgba(59,130,246,0.06); }
.terms-box.terms-agreed { border-color: #22c55e; background: rgba(34,197,94,0.06); }
.terms-box.terms-rejected { border-color: #f87171; background: rgba(248,113,113,0.06); }

.cal-chip.job { background: rgba(59,130,246,0.12); border-left: 3px solid #3b82f6; }

/* SLA target editor on the Settings page */
.sla-grid { display: grid; grid-template-columns: 80px 90px auto 80px 90px auto; gap: 6px 10px; align-items: center; }
.sla-grid input { padding: 6px 8px; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 12px 16px; border-radius: 6px; z-index: 200;
  animation: slidein .2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.reminder-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 12px; }
.reminder-card .head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.reminder-card pre { background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; font-size: 12px; white-space: pre-wrap; margin: 0; }

.helper-note { background: rgba(37,99,235,.08); border: 1px solid rgba(37,99,235,.3); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; font-size: 13px; color: #cbd5e1; }
.helper-warn { background: rgba(217,119,6,.08); border-color: rgba(217,119,6,.3); }

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .sidebar .brand { padding: 0 12px 0 0; }
  .nav-link { padding: 8px 12px; border-left: 0; border-bottom: 3px solid transparent; }
  .nav-link.active { border-left: 0; border-bottom-color: var(--primary); }
  .nav-spacer { display: none; }
  .userbar { width: 100%; border-top: 1px solid var(--border); margin-top: 8px; }
  .main { padding: 16px; }
  .row { grid-template-columns: 1fr; }
}

/* ---- Landing page ---- */
.landing { min-height: 100vh; display: flex; flex-direction: column; }
.landing-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.landing-bar .brand { margin-bottom: 0; }
.hero {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 32px 64px;
  text-align: center;
}
.hero h1 {
  font-size: 44px; line-height: 1.1; margin: 0 0 16px;
  background: linear-gradient(135deg, #60a5fa, #c084fc);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  max-width: 800px;
}
.hero .lead { font-size: 18px; color: var(--muted); max-width: 640px; margin: 0 0 28px; line-height: 1.5; }
button.big { font-size: 16px; padding: 12px 24px; }

.features {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px;
  padding: 0 32px 64px; max-width: 1100px; margin: 0 auto; width: 100%;
}
.feature {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px;
}
.feature .icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, rgba(37,99,235,.2), rgba(124,58,237,.2));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; margin-bottom: 12px;
}
.feature h3 { margin: 0 0 8px; font-size: 16px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.landing-foot {
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  font-size: 13px; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}

@media (max-width: 768px) {
  .landing-bar { padding: 12px 16px; }
  .hero { padding: 40px 16px; }
  .hero h1 { font-size: 30px; }
  .hero .lead { font-size: 16px; }
  .features { padding: 0 16px 32px; }
  .landing-foot { padding: 12px 16px; flex-direction: column; gap: 6px; }
}


/* ---- Calendar ---- */
.cal-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.cal-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 4px 6px; letter-spacing: .5px; text-align: center; }
.cal-day { background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; min-height: 96px; padding: 6px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.cal-day.outside { opacity: 0.35; }
.cal-day.today { border-color: var(--primary); background: rgba(37,99,235,.08); }
.cal-day .num { font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.cal-day.today .num { color: #93c5fd; }
.cal-chip { background: var(--panel-2); border-left: 3px solid var(--primary); padding: 2px 6px; border-radius: 3px; font-size: 11px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip:hover { background: #334155; }
.cal-chip.crit { border-left-color: #f87171; }
.cal-chip.warn { border-left-color: #fbbf24; }
.cal-chip.ok   { border-left-color: #4ade80; }
.cal-chip.expired { border-left-color: #94a3b8; opacity: 0.6; }
@media (max-width: 768px) {
  .cal-day { min-height: 70px; padding: 4px; }
  .cal-chip { font-size: 10px; padding: 1px 4px; }
}


/* ---- Light theme ---- */
html, body { transition: background-color .15s, color .15s; }
body.light {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --input-bg: #f8fafc;
  --row-hover: rgba(15,23,42,.04);
}
body.light a { color: #1d4ed8; }
body.light button:hover { background: #e2e8f0; }
body.light th { background: #f1f5f9; }
body.light .modal-backdrop { background: rgba(15,23,42,.45); }
body.light .badge.ok      { background: rgba(22,163,74,.15);  color: #15803d; }
body.light .badge.warn    { background: rgba(217,119,6,.18);  color: #b45309; }
body.light .badge.crit    { background: rgba(220,38,38,.18);  color: #b91c1c; }
body.light .badge.expired { background: rgba(100,116,139,.18); color: #475569; }
body.light .badge.role    { background: rgba(37,99,235,.15);  color: #1d4ed8; }
body.light .badge.sent    { background: rgba(22,163,74,.15);  color: #15803d; }
body.light .badge.error   { background: rgba(220,38,38,.18);  color: #b91c1c; }
body.light .helper-note   { color: #334155; }
body.light .login-error   { color: #b91c1c; }
body.light .cal-day.today { background: rgba(37,99,235,.06); }


/* ---- Search ---- */
.sb-search {
  margin: 0 16px 12px; padding: 8px 10px;
  background: var(--input-bg); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 13px;
}
.sb-search:hover { color: var(--text); }
.sb-search kbd {
  margin-left: auto; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.search-input {
  width: 100%; font-size: 16px; padding: 12px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
}
.search-input:focus { outline: 2px solid var(--primary); }
.search-results { max-height: 50vh; overflow-y: auto; margin-top: 12px; }
.search-group-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; padding: 8px 4px 4px; }
.search-item {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.search-item:hover, .search-item.active { background: var(--panel-2); }
.search-item .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.search-empty { padding: 24px; text-align: center; color: var(--muted); }
