/* Solara IM — modern UI (dark, high-contrast, responsive) */

:root {
  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", monospace;

  --bg-deep: #050810;
  --bg: #0a0f1a;
  --bg-elevated: #0f1629;
  --surface: #121a2e;
  --surface-hover: #182238;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --muted-dim: #64748b;

  /* Form controls: lighter than --surface (#121a2e) so fields read clearly on cards */
  --input-bg: #1a253f;
  --input-bg-hover: #243356;
  --input-border: rgba(255, 255, 255, 0.2);
  --input-border-hover: rgba(255, 255, 255, 0.32);
  --input-placeholder: #64748b;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-muted: rgba(99, 102, 241, 0.15);
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --shadow-input:
    0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 1px 2px rgba(0, 0, 0, 0.35);
  --focus: 0 0 0 3px rgba(99, 102, 241, 0.45);
  --header-h: 56px;
  --sidebar-w: 240px;
  --content-max: 1200px;
  --step: 4px;

  /* Spacing scale (use across layout + forms) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-page-y: clamp(1.25rem, 4vw, 2rem);
  --space-page-x: clamp(1rem, 3vw, 1.5rem);

  --heading-page: clamp(1.375rem, 2.5vw, 1.625rem);
  --heading-section: 1.125rem;
  --heading-label: 0.6875rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 100% -20%, rgba(99, 102, 241, 0.12), transparent 50%),
    radial-gradient(ellipse 80% 50% at 0% 100%, rgba(34, 211, 238, 0.06), transparent 45%);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}
a:hover {
  color: #67e8f9;
}

/* ——— App frame ——— */
.app-frame {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ——— Top bar ——— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 calc(var(--step) * 4);
  background: rgba(10, 15, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}
.sidebar-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 1.2;
}
.brand a {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
  background: linear-gradient(135deg, #e0e7ff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand a:hover {
  opacity: 0.9;
  -webkit-text-fill-color: #c7d2fe;
}
.brand__tag {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 200px;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface);
}

/* ——— Layout: sidebar + main ——— */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: calc(var(--step) * 4);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
}

.sidebar__title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-dim);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sidebar-nav a:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.sidebar-nav a .nav-icon {
  display: inline-flex;
  width: 1.25rem;
  justify-content: center;
  font-size: 0.95rem;
  opacity: 0.85;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--header-h);
  z-index: 85;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  appearance: none;
}
.sidebar-backdrop.is-visible {
  display: block;
}

body.sidebar-open {
  overflow: hidden;
}

@media (min-width: 901px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

.main {
  flex: 1;
  min-width: 0;
  padding: var(--space-page-y) var(--space-page-x) calc(var(--space-page-y) * 2);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

/* ——— Page structure ——— */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  margin: 0;
  font-size: var(--heading-page);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.22;
  color: var(--text);
}
.page-header .lead {
  margin: var(--space-2) 0 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--muted);
  max-width: 48ch;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar--inline {
  padding: var(--space-3) var(--space-4);
}

/* ——— Cards & panels ——— */
.card {
  background: var(--surface);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card.narrow {
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}
.card + .card {
  margin-top: var(--space-5);
}

.panel {
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  background: rgba(15, 22, 46, 0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--heading-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-dim);
}

h1 {
  font-size: var(--heading-page);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 0 var(--space-3);
  color: var(--text);
}
h2 {
  font-size: var(--heading-section);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.015em;
  margin: var(--space-6) 0 var(--space-3);
  color: var(--text);
}
.main section > h2:first-child,
.card > h2:first-child {
  margin-top: 0;
}

/* ——— Forms ——— */
label,
.label {
  display: block;
  margin: var(--space-4) 0 var(--space-2);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
}
label:first-child,
.form-row:first-child label,
.card > form > label:first-of-type,
.panel > form > label:first-of-type {
  margin-top: 0;
}

/* Default missing type= is text in HTML5; [type="text"] alone misses those inputs */
input:not([type]),
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input[type="tel"],
input[type="url"],
input[type="file"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.625rem 0.875rem;
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--text);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-input);
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}
input:not([type]),
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input[type="tel"],
input[type="url"],
select {
  min-height: 2.75rem;
}
textarea {
  min-height: 7.5rem;
  resize: vertical;
  line-height: 1.55;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}
input[type="file"] {
  min-height: auto;
  padding: var(--space-3);
  cursor: pointer;
}
select {
  cursor: pointer;
  appearance: none;
  background-color: var(--input-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M3 4.5h6L6 9 3 4.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}
input:not([type])::placeholder,
input[type="text"]::placeholder,
input[type="email"]::placeholder,
input[type="password"]::placeholder,
input[type="number"]::placeholder,
input[type="search"]::placeholder,
input[type="date"]::placeholder,
input[type="datetime-local"]::placeholder,
input[type="tel"]::placeholder,
input[type="url"]::placeholder,
textarea::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}
input:not([type]):hover,
input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="search"]:hover,
input[type="date"]:hover,
input[type="datetime-local"]:hover,
input[type="tel"]:hover,
input[type="url"]:hover,
input[type="file"]:hover,
select:hover,
textarea:hover {
  background-color: var(--input-bg-hover);
  border-color: var(--input-border-hover);
}
input:not([type]):focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="file"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus), var(--shadow-input);
}
input:not([type]):disabled,
input[type="text"]:disabled,
input[type="email"]:disabled,
input[type="password"]:disabled,
input[type="number"]:disabled,
input[type="search"]:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="tel"]:disabled,
input[type="url"]:disabled,
input[type="file"]:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  gap: var(--space-4);
}
@media (min-width: 720px) {
  .form-grid--2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
  align-items: center;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.checkbox-row input {
  width: auto;
}

/* ——— Buttons ——— */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
button:active,
.btn:active {
  transform: translateY(1px);
}

.btn,
button[type="submit"] {
  background: linear-gradient(180deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset;
}
.btn:hover,
button[type="submit"]:hover {
  background: linear-gradient(180deg, #818cf8 0%, #6366f1 100%);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn--ghost:hover {
  color: var(--text);
  background: var(--surface);
}

.btn--sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

/* ——— Ticket attachment panel ——— */
.attachment-panel__section {
  margin-bottom: var(--space-5);
}
.attachment-panel__section:last-child {
  margin-bottom: 0;
}
.attachment-panel__section-title {
  margin: 0 0 var(--space-3);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-dim);
}
.attachment-panel__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.attachment-panel__item {
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) 0;
}
.attachment-panel__item:last-child {
  border-bottom: none;
}
.attachment-panel__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}
.attachment-panel__name {
  flex: 1 1 12rem;
  min-width: 0;
  word-break: break-word;
  font-size: 0.9rem;
}
.attachment-panel__badge {
  display: inline-block;
  margin-right: var(--space-2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.attachment-panel__meta {
  font-size: 0.75rem;
  flex: 1 1 auto;
}
.attachment-panel__actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-left: auto;
}
.attachment-panel__nested {
  margin-top: var(--space-2);
}
@media (max-width: 640px) {
  .attachment-panel__row {
    flex-direction: column;
    align-items: flex-start;
  }
  .attachment-panel__actions {
    margin-left: 0;
  }
}

/* ——— Tables ——— */
.table-wrap {
  overflow-x: auto;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
}
.table tbody tr {
  transition: background 0.12s ease;
}
.table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}
.table td a {
  font-weight: 500;
}

/* ——— Badges ——— */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.badge--low {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
}
.badge--normal {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
}
.badge--high {
  background: rgba(251, 191, 36, 0.15);
  color: #fcd34d;
}
.badge--urgent {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

/* ——— Tickets / threads ——— */
.reply {
  margin: 0.75rem 0;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(8, 12, 20, 0.5);
}
.reply header {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.reply.internal {
  border-color: rgba(249, 115, 22, 0.45);
  background: rgba(249, 115, 22, 0.06);
}

.ticket-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.75rem;
}
.ticket-number {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.canned-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.canned-strip .btn--ghost {
  max-width: 100%;
  text-align: left;
  justify-content: flex-start;
}

/* ——— Auth pages ——— */
.auth-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--step) * 6) calc(var(--step) * 4);
  min-height: calc(100vh - var(--header-h));
}

.auth-card {
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
}
.auth-card .subtitle {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.app--guest .main {
  max-width: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
.app--guest .layout {
  flex: 1;
}

/* ——— Utilities ——— */
.muted {
  color: var(--muted);
}
.error {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.9rem;
}
.flash-info {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.25);
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.rich-text {
  line-height: 1.65;
}
.rich-text p {
  margin: 0.75rem 0;
}

/* ——— Admin settings ——— */
.settings-section-title {
  margin: 0 0 var(--space-5);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.field-hint {
  margin: var(--space-2) 0 var(--space-4);
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  max-width: 65ch;
}
.settings-form .form-grid + .field-hint {
  margin-top: var(--space-3);
}
textarea.monospace,
input.monospace {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.settings-form .checkbox-row {
  margin: 0.5rem 0;
}

/* ——— Responsive ——— */
@media (max-width: 900px) {
  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.sidebar--open {
    transform: translateX(0);
  }
  .main {
    padding-left: calc(var(--step) * 3);
    padding-right: calc(var(--step) * 3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
