/* ---------------------------------------------------------------------------
   CONZELT client portal - design tokens and base styles.

   One palette, defined once on :root and overridden wholesale for dark mode,
   so no component ever hard-codes a colour.
--------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --ink-900: #10131a;
  --ink-700: #333a48;
  --ink-500: #5b6474;
  --ink-400: #808a9b;

  --surface: #ffffff;
  --surface-sunken: #f5f6f8;
  --surface-raised: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cbd0d9;

  --accent: #1f4fd8;
  --accent-hover: #1a43b8;
  --accent-soft: #eaf0ff;
  --accent-ink: #ffffff;

  --success: #1a7f4b;
  --success-soft: #e6f4ec;
  --warning: #9a6208;
  --warning-soft: #fdf3e0;
  --danger: #b3261e;
  --danger-soft: #fdecea;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgb(16 19 26 / 6%);
  --shadow-md: 0 4px 16px rgb(16 19 26 / 8%);
  --shadow-lg: 0 16px 48px rgb(16 19 26 / 16%);

  --font-sans:
    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'Cascadia Mono', Menlo, monospace;

  --header-height: 60px;
  --sidebar-width: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --ink-900: #eef1f6;
    --ink-700: #c3cad6;
    --ink-500: #939cab;
    --ink-400: #6f7887;

    --surface: #14171d;
    --surface-sunken: #0e1116;
    --surface-raised: #1b1f27;
    --border: #282d37;
    --border-strong: #3a4150;

    --accent: #6f95ff;
    --accent-hover: #85a6ff;
    --accent-soft: #1a2340;
    --accent-ink: #0e1116;

    --success: #62c48d;
    --success-soft: #16281f;
    --warning: #e0ac5b;
    --warning-soft: #2b2113;
    --danger: #ef8079;
    --danger-soft: #2d1817;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-md: 0 4px 16px rgb(0 0 0 / 45%);
    --shadow-lg: 0 16px 48px rgb(0 0 0 / 55%);
  }
}

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

html,
body,
#root {
  height: 100%;
}

body {
  margin: 0;
  background: var(--surface-sunken);
  color: var(--ink-900);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 22px;
}
h2 {
  font-size: 17px;
}

p {
  margin: 0;
}

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

/* Visible focus for keyboard users on every interactive element. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --- Layout ------------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--ink-900);
}

.app-brand span {
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-400);
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  align-items: start;
}

.app-sidebar {
  position: sticky;
  top: var(--header-height);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 12px;
  height: calc(100vh - var(--header-height));
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.app-main {
  padding: 24px 28px 64px;
  max-width: 1180px;
  width: 100%;
}

.nav-link {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-700);
  font-weight: 500;
}

.nav-link:hover {
  background: var(--surface-sunken);
  text-decoration: none;
}

.nav-link[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-section {
  margin: 18px 0 6px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-400);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head p {
  margin-top: 4px;
  color: var(--ink-500);
}

/* --- Surfaces ----------------------------------------------------------- */

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

.card-pad {
  padding: 20px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

/* --- Forms -------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 550;
  font-size: 13px;
  color: var(--ink-700);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--ink-900);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.field-error {
  font-size: 12.5px;
  color: var(--danger);
}

.hint {
  font-size: 12.5px;
  color: var(--ink-500);
}

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-900);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 120ms ease,
    border-color 120ms ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  border-color: var(--border-strong);
  color: var(--ink-700);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-sunken);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-500);
  padding: 6px 9px;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-sunken);
  color: var(--ink-900);
}

.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

/* --- Table -------------------------------------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-400);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--surface-sunken);
}

.table-scroll {
  overflow-x: auto;
}

.cell-title {
  font-weight: 550;
  color: var(--ink-900);
}

.cell-sub {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--ink-500);
}

.cell-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.numeric {
  font-variant-numeric: tabular-nums;
  color: var(--ink-500);
  white-space: nowrap;
}

/* --- Badges ------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-sunken);
  color: var(--ink-500);
  white-space: nowrap;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}
.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}
.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

/* --- Feedback ----------------------------------------------------------- */

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  margin-bottom: 14px;
}

.alert-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 28%, transparent);
  color: var(--danger);
}

.alert-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 28%, transparent);
  color: var(--success);
}

.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-500);
}

.empty-state h2 {
  margin-bottom: 6px;
  color: var(--ink-900);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2s;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}

.progress {
  height: 6px;
  background: var(--surface-sunken);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 160ms ease;
}

/* --- Auth screens ------------------------------------------------------- */

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 396px;
  padding: 30px;
}

.auth-card h1 {
  margin-bottom: 6px;
}

.auth-card > p {
  margin-bottom: 22px;
  color: var(--ink-500);
}

/* --- Dialog ------------------------------------------------------------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(16 19 26 / 45%);
  z-index: 50;
}

.dialog {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 24px;
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.dialog h2 {
  margin-bottom: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* --- Small screens ------------------------------------------------------ */

@media (max-width: 860px) {
  .app-body {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .nav-section {
    width: 100%;
    margin: 8px 0 2px;
  }

  .app-main {
    padding: 18px 16px 48px;
  }

  .page-head {
    flex-direction: column;
  }
}

/* --- Server-rendered additions ------------------------------------------
   Classes used by src/layout.php and the public/ pages, which replace the
   inline styles the React prototype relied on.
------------------------------------------------------------------------- */

.header-user {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-identity {
  text-align: right;
  line-height: 1.3;
}

.header-name {
  font-weight: 550;
}

.header-role {
  font-size: 12px;
  color: var(--ink-400);
}

/* Sign-out and row actions are POST forms, which must not break the flow. */
.inline-form {
  display: inline;
  margin: 0;
}

.alert-warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 28%, transparent);
  color: var(--warning);
}

.stack {
  max-width: 560px;
}

.stack + .stack {
  margin-top: 20px;
}

/* Definition list used for the read-only account summary. */
.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 20px;
  margin: 0;
}

.detail-list dt {
  color: var(--ink-500);
}

.detail-list dd {
  margin: 0;
}

.section-title {
  margin-bottom: 14px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-form .input,
.filter-form .select {
  width: auto;
  min-width: 200px;
}

.upload-panel {
  margin-bottom: 20px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.upload-grid .field-wide {
  grid-column: 1 / -1;
}

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

.progress-wrap {
  margin: 4px 0 14px;
}

/* Hidden until an upload starts; toggled with the hidden attribute. */
[hidden] {
  display: none !important;
}

/* Visually hidden but announced by screen readers — used for action-column
   table headers that need a name but no visible label. */
.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;
}
