/* =========================================================================
   Design tokens
   Palette: cool paper background, deep ink-navy text, a deep teal accent
   for trust/security, and warm copper used sparingly for emphasis.
   Type: Fraunces (display serif — gives the "vault" gravity a generic
   sans wouldn't) + Inter (body/UI) + JetBrains Mono (status/meta chips).
   ========================================================================= */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap');

:root {
  --bg:            #EEF3F7;
  --surface:       #FFFFFF;
  --surface-sunken:#F4F8FA;
  --ink:           #0B1633;
  --ink-soft:      #4B5C71;
  --border:        #D9E2EA;
  --accent:        #0B63C9;
  --accent-strong: #084A97;
  --accent-turquoise: #14C4B0;
  --accent-tint:   #E4F3F6;
  --copper:        #C77B3D;
  --error:         #B3452E;
  --error-tint:    #F7E9E5;
  --success:       #1E7A4C;
  --success-tint:  #E4F3EA;
  --gradient-brand: linear-gradient(135deg, var(--accent-turquoise) 0%, var(--accent) 100%);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(11, 22, 51, 0.04), 0 12px 32px -12px rgba(11, 22, 51, 0.18);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
p { margin: 0 0 16px; line-height: 1.5; }
.muted { color: var(--ink-soft); font-size: 0.95rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin: 0 0 10px;
}

/* ---- Brand mark: the actual logo image -------------------------------
   Centered by default (login, register, set-password, change-password all
   sit inside .auth-card). The app header (dashboard/admin) overrides this
   below to sit left-aligned next to the app name instead. */
.brand-mark {
  display: block;
  height: 72px;
  width: auto;
  margin: 0 auto 20px;
  object-fit: contain;
}

/* =========================================================================
   Auth shell (login / register / set-password / change-password)
   ========================================================================= */
.auth-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% -10%, #D7ECEE 0%, transparent 45%),
    radial-gradient(900px 500px at 100% 0%, #DCE9F7 0%, transparent 50%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-card);
}

.auth-card h1 { font-size: 1.7rem; margin-bottom: 6px; }
.auth-switch { margin-top: 20px; font-size: 0.92rem; text-align: center; color: var(--ink-soft); }

form { display: flex; flex-direction: column; }

label {
  font-size: 0.84rem;
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--ink);
}
label:first-of-type { margin-top: 4px; }

input[type="text"],
input[type="email"],
input[type="password"] {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.hint { font-size: 0.8rem; color: var(--ink-soft); margin: 6px 0 0; }

.field-link {
  margin: 8px 0 0;
  text-align: right;
  font-size: 0.85rem;
}

.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 64px; }
.password-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent-strong);
  cursor: pointer;
  padding: 6px 8px;
}

.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.button {
  margin-top: 22px;
  padding: 12px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.button:hover { filter: brightness(0.94); }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.6; cursor: not-allowed; }

.button--ghost {
  display: inline-block;
  margin-top: 18px;
  background: transparent;
  color: var(--accent-strong);
  border: 1.5px solid var(--border);
  text-align: center;
  text-decoration: none;
}
.button--ghost:hover { background: var(--accent-tint); border-color: var(--accent); text-decoration: none; }

.install-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.install-button__icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  border-radius: 4px;
}

.form-message {
  display: none;
  font-size: 0.88rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
}
.form-message.is-visible { display: block; }
.form-message.is-error { background: var(--error-tint); color: var(--error); }
.form-message.is-success { background: var(--success-tint); color: var(--success); }

/* =========================================================================
   App shell (dashboard / admin panel)
   ========================================================================= */
.app-shell { min-height: 100dvh; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
}
.app-header__brand .brand-mark { margin: 0; height: 36px; }

.admin-nav {
  display: flex;
  gap: 4px;
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-nav__link {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
}
.admin-nav__link:hover { background: var(--surface-sunken); color: var(--ink); text-decoration: none; }
.admin-nav__link.is-active { background: var(--accent-tint); color: var(--accent-strong); font-weight: 600; }

.link-button {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}
.link-button:hover { color: var(--accent-strong); border-color: var(--accent); text-decoration: none; }

.app-main { padding: 40px 28px 60px; display: flex; justify-content: center; }
.app-main--wide { display: block; max-width: 1100px; margin: 0 auto; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.dashboard-grid__feed { grid-column: 1 / -1; }

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

select,
textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  resize: vertical;
}
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%234B5C71'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.panel {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-card);
}
.panel--wide { max-width: 820px; }

.panel__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.tabs { display: flex; gap: 4px; background: var(--surface-sunken); padding: 4px; border-radius: var(--radius-sm); }
.tab {
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--ink-soft);
  cursor: pointer;
}
.tab.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: 0 1px 3px rgba(16,32,46,0.12); }

/* ---- Admin table ------------------------------------------------------ */
.user-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.user-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0 10px 10px;
  border-bottom: 1.5px solid var(--border);
}
.user-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.user-table tr:last-child td { border-bottom: none; }

.status-chip {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  display: inline-block;
}
.status-chip--pending  { background: #FBF0E1; color: var(--copper); }
.status-chip--approved { background: var(--success-tint); color: var(--success); }
.status-chip--rejected { background: var(--error-tint); color: var(--error); }
.status-chip--open     { background: #FBF0E1; color: var(--copper); }
.status-chip--closed   { background: var(--success-tint); color: var(--success); }

.status-chip--priority-critical { background: var(--error-tint); color: var(--error); }
.status-chip--priority-high     { background: #FBF0E1; color: var(--copper); }
.status-chip--priority-normal   { background: var(--accent-tint); color: var(--accent-strong); }
.status-chip--priority-low      { background: var(--success-tint); color: var(--success); }

.ticket-overdue { color: var(--error) !important; font-weight: 600; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.row-actions button {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.row-actions .approve-btn { color: var(--success); border-color: #BEE0CC; }
.row-actions .approve-btn:hover { background: var(--success-tint); }
.row-actions .reject-btn { color: var(--error); border-color: #E9C3B7; }
.row-actions .reject-btn:hover { background: var(--error-tint); }

.empty-state { text-align: center; color: var(--ink-soft); padding: 32px 0 !important; }

/* ---- Table horizontal scroll wrapper (admin grid columns get narrow) -- */
.table-scroll { overflow-x: auto; }
.table-scroll .user-table { min-width: 480px; }

/* ---- Ticket feed -------------------------------------------------------- */
.ticket-feed { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 480px; overflow-y: auto; }
.ticket-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-sunken);
}
.ticket-item--clickable { cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease; }
.ticket-item--clickable:hover,
.ticket-item--clickable:focus-visible { border-color: var(--accent); background: var(--surface); }

.ticket-item__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.ticket-item__type { font-weight: 600; font-size: 0.92rem; }
.ticket-item__desc { margin: 0 0 6px; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.45; }
.ticket-item__meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft); letter-spacing: 0.01em; }
.ticket-item__badges { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- Admin priority summary cards -------------------------------------- */
.priority-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0 20px;
}
.priority-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: center;
  background: var(--surface-sunken);
}
.priority-card__count { display: block; font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; }
.priority-card__label { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); }
.priority-card--critical { border-color: #E9C3B7; background: var(--error-tint); }
.priority-card--critical .priority-card__count { color: var(--error); }
.priority-card--high { border-color: #F0DCB8; background: #FBF0E1; }
.priority-card--high .priority-card__count { color: var(--copper); }
.priority-card--normal { border-color: #C7DEE8; background: var(--accent-tint); }
.priority-card--normal .priority-card__count { color: var(--accent-strong); }
.priority-card--low { border-color: #BEE0CC; background: var(--success-tint); }
.priority-card--low .priority-card__count { color: var(--success); }

/* ---- Admin ticket table ------------------------------------------------- */
.ticket-table .ticket-row { cursor: pointer; }
.ticket-table .ticket-row:hover { background: var(--surface-sunken); }
.ticket-row__sub { font-size: 0.78rem; color: var(--ink-soft); }

/* ---- Ticket modal field grid -------------------------------------------- */
.modal-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 4px;
}
.modal-fields label { margin: 0 0 6px; display: block; }
.modal-fields select { width: 100%; padding: 9px 30px 9px 11px; font-size: 0.9rem; }

/* ---- Explorer pages (Ticket Users / Communities) ------------------------ */
.explorer-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  align-items: start;
}
.explorer-panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.explorer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
  margin-top: 4px;
}
.explorer-search {
  width: 100%;
  margin: 14px 0 12px;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-family: var(--font-body);
  font-size: 0.9rem;
}
.explorer-search:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-tint); }

.explorer-detail { min-height: 200px; }
.explorer-detail .ticket-feed { max-height: 560px; }

/* ---- Tree view ----------------------------------------------------------- */
.explorer-tree { max-height: 620px; overflow-y: auto; }
.tree-node { margin-bottom: 2px; }
.tree-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 4px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.88rem;
  text-align: left;
  color: var(--ink);
}
.tree-row:hover { background: var(--surface-sunken); }
.tree-chevron { width: 12px; flex-shrink: 0; color: var(--ink-soft); font-size: 0.7rem; }
.tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
  background: var(--surface-sunken);
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}
.tree-row--ticket { padding-left: 20px; justify-content: space-between; }
.tree-ticket-badges { display: flex; gap: 4px; flex-shrink: 0; }
.tree-children { padding-left: 18px; border-left: 1px solid var(--border); margin-left: 10px; }
.empty-state--tree { padding: 8px 0 !important; font-size: 0.82rem; }

/* ---- User detail panel ---------------------------------------------------- */
.user-detail-stats { display: flex; gap: 24px; margin: 14px 0; }
.user-detail-stats__num { display: block; font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; }
.user-detail-stats__label { font-family: var(--font-mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); }
.user-detail-communities { font-size: 0.88rem; }
.ticket-history-heading { font-size: 1.05rem; margin: 20px 0 4px; }

@media (max-width: 900px) {
  .explorer-grid { grid-template-columns: 1fr; }
}

/* ---- Ticket detail modal ------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 22, 51, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-card);
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  border: none;
  background: var(--surface-sunken);
  border-radius: 50%;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
}
.modal-close:hover { background: var(--accent-tint); color: var(--accent-strong); }
.modal-description {
  white-space: pre-wrap;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0 0 8px;
}
.modal-actions { display: flex; justify-content: flex-end; }
.modal-actions .button { margin-top: 10px; }

@media (max-width: 900px) {
  .dashboard-grid,
  .admin-grid { grid-template-columns: 1fr; }
  .app-main--wide { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 560px) {
  .auth-card { padding: 32px 24px; }
  .app-header { padding: 14px 18px; }
  .app-main { padding: 24px 14px 48px; }
  .panel { padding: 22px; }
  .user-table thead { display: none; }
  .user-table, .user-table tbody, .user-table tr, .user-table td { display: block; width: 100%; }
  .user-table tr { border-bottom: 1px solid var(--border); padding: 12px 0; }
  .user-table td { border-bottom: none; padding: 4px 0; }
  .row-actions { justify-content: flex-start; margin-top: 8px; }
  .modal { padding: 24px 20px; }
  .priority-cards { grid-template-columns: repeat(2, 1fr); }
  .modal-fields { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
