/* ============================================================
   iServerSupport — Customer Portal
   Design system: Inter + Font Awesome 6, semantic color tokens,
   fixed-sidebar layout grid. Ported from the BashPilot dashboard
   design system (tokens/structure only — no BashPilot branding,
   tracking, or copy).
   ============================================================ */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg-body: #f4f6fb;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-subtle: #f8f9fd;
  --bg-hover: #eef1f8;

  /* Sidebar — exact match to the BashPilot dashboard's own tokens. */
  --sidebar-bg: #272b35;
  --sidebar-bg-2: #2d323d;
  --sidebar-bg-hover: #353b47;
  --sidebar-border: #1b1f27;
  --sidebar-text: #d1d5db;
  --sidebar-text-muted: #9ca3af;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-2: #8b5cf6;
  --accent-soft: #eef0ff;
  --accent-contrast: #ffffff;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --accent-rgb: 99, 102, 241;

  --border: #e6e9f2;
  --text: #101423;
  --muted: #626b80;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-text: #047857;
  --success-border: #a7f3d0;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fde68a;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --danger-border: #fecaca;

  --purple: #8b5cf6;
  --purple-bg: #f5f3ff;
  --purple-text: #6d28d9;
  --purple-border: #ddd6fe;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16,20,35,.05), 0 1px 6px rgba(16,20,35,.04);
  --shadow-md: 0 6px 24px rgba(16,20,35,.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-body);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

* { scrollbar-width: thin; scrollbar-color: rgba(148,163,184,.35) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(148,163,184,.3); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,.5); }

/* ============================================================
   LAYOUT — fixed sidebar + flexible content, no stacked topbar
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar-bg-2) 0%, var(--sidebar-bg) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 1.15rem 1.1rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800; flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), .45);
}
.sidebar-brand .label { font-weight: 800; font-size: 1.02rem; color: #fff; letter-spacing: -.01em; }

.sidebar-nav {
  padding: 1.1rem .85rem;
  flex: 1;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--sidebar-text-muted);
  margin: .2rem .5rem .5rem;
  font-weight: 700;
  opacity: .8;
}

.sidebar-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .68rem .8rem; border-radius: 10px;
  color: var(--sidebar-text); font-size: .92rem; font-weight: 500;
  margin-bottom: .2rem; position: relative;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; opacity: .9; margin-top: .1rem; }
.sidebar-link:hover { background: var(--sidebar-bg-hover); color: #fff; text-decoration: none; }
.sidebar-link.active {
  background: linear-gradient(90deg, rgba(99,102,241,.28), rgba(139,92,246,.08));
  color: #fff;
}
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: linear-gradient(180deg, #6366f1, #8b5cf6);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px rgba(99,102,241,.8);
}
.sidebar-sublink { margin: 0 0 .1rem 1.4rem; padding: .5rem .7rem; border-left: 1px solid rgba(255,255,255,.18); border-radius: 0 10px 10px 0; }
.sidebar-sublink i { font-size: .9rem; width: 18px; }
.sidebar-sublink .label { font-weight: 500; }
.sidebar-back { color: var(--sidebar-text-muted); font-size: .84rem; }
.sidebar-site { display: flex; flex-direction: column; gap: .2rem; margin: .5rem .3rem 1.1rem; padding: .8rem .9rem; border-radius: 12px; min-width: 0;
  background: linear-gradient(135deg, rgba(99,102,241,.28), rgba(139,92,246,.10)); border: 1px solid rgba(255,255,255,.08); }
.sidebar-site b { color: #fff; font-size: .9rem; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }   /* one line; long domains are cut with an ellipsis (full name on hover) */
.sidebar-site small { color: var(--sidebar-text-muted); font-size: .72rem; }
.sidebar-link .text { display: flex; flex-direction: column; gap: .1rem; min-width: 0; line-height: 1.3; }
.sidebar-link .label { font-size: .88rem; font-weight: 600; }
.sidebar-link .sub {
  font-size: .72rem; font-weight: 400; color: var(--sidebar-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-link.active .sub { color: rgba(255,255,255,.7); }

.sidebar-foot {
  padding: 1rem 1.1rem 1.1rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: .7rem;
}
.sidebar-foot .who-row { display: flex; align-items: center; gap: .65rem; }
.sidebar-foot .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}
.sidebar-foot .who { min-width: 0; line-height: 1.35; }
.sidebar-foot strong {
  color: #fff; display: block; font-size: .85rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-foot .role {
  font-size: .72rem; color: var(--sidebar-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.sidebar-tag { text-align: center; font-size: .68rem; color: var(--sidebar-text-muted); opacity: .6; }

.logout-btn {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .55rem; border-radius: 9px; border: 1px solid rgba(239,68,68,.35);
  color: #f87171; font-size: .82rem; font-weight: 600; background: rgba(239,68,68,.06);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s ease;
}
.logout-btn:hover { background: rgba(239,68,68,.14); text-decoration: none; color: #fca5a5; }

.main { display: flex; flex-direction: column; background: var(--bg-body); min-width: 0; }
.content { padding: 1.75rem 2rem; flex: 1; }

.filter-bar { display: flex; gap: 8px; padding: 14px 18px 0; flex-wrap: wrap; }
.filter-bar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--bg-card); font-family: inherit; }

/* Auth pages (login/register) render without the sidebar */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 20px;
  background: var(--bg-body);
}

/* ============================================================
   SHARED COMPONENTS
   ============================================================ */
.container { max-width: 880px; margin: 0 auto; width: 100%; }
.container-narrow { max-width: 420px; }

.page-title { font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em; margin: 0 0 4px; color: var(--text); }
.page-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.brand-mark {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 18px; color: var(--text);
}
.brand-mark .mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), .35);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: 0 2px 10px rgba(var(--accent-rgb),.3); }
.btn-primary:hover { background: var(--accent-grad); color: #fff; filter: brightness(1.08); box-shadow: 0 4px 14px rgba(var(--accent-rgb),.4); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-input, .form-select, textarea.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-input:focus, .form-select:focus, textarea.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.form-error {
  background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger-text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; display: none;
}

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  border: 1px solid transparent;
}
.badge-gray { background: var(--bg-subtle); color: var(--muted); border-color: var(--border); }
.badge-blue { background: var(--accent-soft); color: var(--accent); border-color: #bfdbfe; }
.badge-green { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-orange { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-red { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }

.ticket-row {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
  transition: background .12s ease;
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: var(--bg-subtle); text-decoration: none; }
.ticket-row-icon {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  background: var(--accent-soft); color: var(--accent);
}
.ticket-row-main { min-width: 0; flex: 1; }
.ticket-row-subject { font-weight: 700; font-size: 14.5px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-row-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ticket-row-right { text-align: right; flex-shrink: 0; font-size: 12px; color: var(--muted); }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty i { font-size: 30px; margin-bottom: 12px; display: block; opacity: .4; color: var(--accent); }

/* ── Conversation thread (full-width feed, color-coded by who's talking:
   blue = customer, accent = staff -- not a chat-bubble layout, reads much
   better for long support messages) ──────────────────────────────────── */
#thread { padding: 18px; }
.tmsg {
  display: flex; gap: 14px; padding: 18px 20px; border-radius: 12px; border: 1px solid transparent;
  margin-bottom: 12px;
}
.tmsg:last-child { margin-bottom: 0; }
.tmsg.customer { background: #ffffff; border-color: #ded4fb; }
.tmsg.admin { background: #eef0ff; border-color: #c7d2fe; }
.tmsg-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; margin-top: 2px;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #fff;
}
.tmsg.customer .tmsg-avatar { background: var(--accent-2); }
.tmsg.admin .tmsg-avatar { background: var(--accent); }
.tmsg-body { flex: 1; min-width: 0; }
.tmsg-header { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; flex-wrap: wrap; }
.tmsg-author { font-weight: 700; font-size: 13.5px; color: #1e293b; }
.tmsg-role { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 20px; }
.tmsg.customer .tmsg-role { background: rgba(139,92,246,.12); color: var(--accent-2); }
.tmsg.admin .tmsg-role { background: var(--accent-soft); color: var(--accent); }
.tmsg-time { font-size: 11.5px; color: #64748b; margin-left: auto; white-space: nowrap; }
.tmsg-content { font-size: 13.75px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; color: #1e293b; }
.tmsg-attachments { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.tmsg-attachments a {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500;
  padding: 7px 12px; background: rgba(255,255,255,.6); border: 1px solid rgba(0,0,0,.08); border-radius: 8px;
  text-decoration: none; color: #1e293b; transition: background .12s ease, border-color .12s ease;
}
.tmsg-attachments a:hover { background: #fff; border-color: var(--accent); }
.tmsg-attachments a i { color: #64748b; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 999;
  background: var(--text); color: #fff; padding: 11px 18px;
  border-radius: var(--radius-sm); font-size: 13.5px; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(8px); transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 8px; color: var(--muted); padding: 24px; justify-content: center; }

/* ============================================================
   RESPONSIVE — sidebar collapses to a horizontal top bar rather
   than the old cramped two-row topnav (no mid-header divider).
   ============================================================ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 68px 1fr; }
  .sidebar-brand .label, .sidebar-link .text { display: none; }
  .sidebar-site { display: none; }
  .sidebar-brand { justify-content: center; padding: 1.1rem .5rem; }
  .sidebar-link { justify-content: center; padding: .68rem 0; }
  .sidebar-foot { display: none; }
  .content { padding: 1.1rem .9rem; }
}

@media (max-width: 640px) {
  .container { padding: 0; }
  .tmsg { padding: 16px; gap: 10px; }
}
