/* LegacySwitch application styles.
 *
 * Oat supplies the semantic baseline. This file only themes Oat for the app,
 * fills its few component gaps, and preserves LegacySwitch's information
 * hierarchy: the check-in action, switch state, record tables, and readable
 * delivered messages.
 */

:root {
  color-scheme: light dark;
  --container-max: 56rem;
  --container-pad: 1rem;
  --radius-small: 0.25rem;
  --radius-medium: 0.625rem;
  --radius-large: 0.875rem;
  --shadow-small: 0 1px 2px rgb(15 23 42 / 0.05);
  --shadow-medium: 0 10px 28px rgb(15 23 42 / 0.07);

  --background: light-dark(#f7f9fc, #0b1020);
  --foreground: light-dark(#172033, #e8eef8);
  --card: light-dark(#ffffff, #111a2b);
  --card-foreground: light-dark(#172033, #e8eef8);
  --primary: light-dark(#0f766e, #5eead4);
  --primary-foreground: light-dark(#ffffff, #08211f);
  --secondary: light-dark(#edf1f6, #1a2538);
  --secondary-foreground: light-dark(#263247, #e8eef8);
  --muted: light-dark(#f0f3f8, #172235);
  --muted-foreground: light-dark(#66758c, #9aabc3);
  --faint: light-dark(#fafbfd, #0d1525);
  --faint-foreground: light-dark(#8a97aa, #71839d);
  --accent: light-dark(#eaf2f3, #193138);
  --danger: light-dark(#b93832, #ff938c);
  --danger-foreground: light-dark(#ffffff, #2a0b09);
  --success: light-dark(#16794b, #72dfa6);
  --success-foreground: light-dark(#ffffff, #082117);
  --warning: light-dark(#9a5a08, #f4bd62);
  --warning-foreground: light-dark(#ffffff, #281b06);
  --border: light-dark(#dfe5ed, #293449);
  --input: light-dark(#d5dde8, #344159);
  --ring: light-dark(#0f766e, #5eead4);
}

html.light {
  color-scheme: light;
}

html.dark {
  color-scheme: dark;
}

body {
  min-height: 100vh;
}

.container {
  max-width: var(--container-max);
  padding-inline: var(--container-pad);
}

a {
  color: var(--primary);
  text-decoration-underline-offset: 0.15em;
}

h1,
h2,
h3 {
  color: var(--foreground);
  letter-spacing: -0.02em;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.45rem, 1.3rem + 0.55vw, 1.75rem);
}

h2 {
  margin: 0 0 0.35rem;
  font-size: 1.125rem;
}

h3 {
  margin: 1.25rem 0 0.4rem;
  font-size: 0.95rem;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--background) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.site-header .container {
  display: flex;
  min-height: 4rem;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.site-title {
  margin-inline-end: auto;
  color: var(--foreground);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.site-title:hover {
  color: var(--primary);
}

.nav-links,
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.nav-links {
  font-size: 0.875rem;
}

.nav-links a {
  color: var(--muted-foreground);
  text-decoration: none;
}

.nav-links a:hover {
  color: var(--foreground);
}

.theme-toggle {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--muted);
}

.theme-choice,
.logout-button,
.link-button {
  appearance: none;
  border: 0;
  background: none;
  box-shadow: none;
  font: inherit;
  cursor: pointer;
  transform: none;
}

.theme-choice {
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-full);
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
}

.theme-choice:hover {
  background: transparent;
  color: var(--foreground);
}

.theme-choice.active {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-small);
}

.logout-form {
  display: inline-flex;
}

.logout-button {
  padding: 0;
  color: var(--muted-foreground);
  font-size: 0.8rem;
  font-weight: 400;
}

.logout-button:hover {
  background: none;
  color: var(--foreground);
}

main.container {
  padding-block: 2rem 1.25rem;
}

.site-footer {
  padding-block: 1rem 2rem;
  color: var(--faint-foreground);
  font-size: 0.8rem;
}

.card {
  margin-block-end: 1rem;
  box-shadow: var(--shadow-small);
}

.card > :first-child {
  margin-block-start: 0;
}

.card > :last-child {
  margin-block-end: 0;
}

.danger-zone {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.subtitle,
.card-hint {
  margin: 0 0 1rem;
  color: var(--muted-foreground);
  font-size: 0.9rem;
}

.section-label {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
}

.button-row > form {
  margin: 0;
}

.card-action {
  margin-block-start: 1.25rem;
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-block: 1rem;
}

.hero-stat {
  padding: 0.9rem 1rem;
  background: var(--muted);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: var(--radius-medium);
}

.hero-stat .label,
.status-line {
  color: var(--muted-foreground);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.hero-stat .label {
  display: block;
  margin-block-end: 0.25rem;
}

.hero-stat .value {
  display: block;
  color: var(--foreground);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.35;
}

.hero-stat .hint {
  display: block;
  margin-block-start: 0.2rem;
}

.status-line {
  margin: 0;
}

.status-ACTIVE {
  color: var(--success);
}

.status-WARNING,
.status-GRACE_PERIOD,
.status-TRIGGERED {
  color: var(--danger);
}

.status-PAUSED {
  color: var(--muted-foreground);
}

.alert {
  display: block;
  margin: 0 0 1rem;
  padding: 0.8rem 1rem;
  color: var(--foreground);
  background: var(--muted);
  border: 1px solid var(--border);
  border-inline-start: 0.25rem solid var(--border);
  border-radius: var(--radius-medium);
  font-size: 0.875rem;
  line-height: 1.55;
}

.alert[data-variant="danger"],
.alert[data-variant="error"] {
  background: color-mix(in srgb, var(--danger) 8%, var(--card));
  border-color: color-mix(in srgb, var(--danger) 25%, var(--border));
  border-inline-start-color: var(--danger);
}

.alert[data-variant="success"] {
  background: color-mix(in srgb, var(--success) 8%, var(--card));
  border-color: color-mix(in srgb, var(--success) 25%, var(--border));
  border-inline-start-color: var(--success);
}

.alert[data-variant="warning"] {
  background: color-mix(in srgb, var(--warning) 8%, var(--card));
  border-color: color-mix(in srgb, var(--warning) 25%, var(--border));
  border-inline-start-color: var(--warning);
}

.alert-spaced {
  margin-block-start: 1rem;
}

.info-box,
.disclaimer {
  color: var(--foreground);
}

.disclaimer {
  margin-block-end: 1rem;
  font-size: 0.85rem;
}

.hint {
  display: block;
  margin-block-start: 0.25rem;
  color: var(--muted-foreground);
  font-size: 0.78rem;
}

.button,
button {
  text-decoration: none;
}

a.button {
  color: var(--primary-foreground);
}

a.button.outline {
  color: var(--foreground);
}

a.button[data-variant="danger"] {
  color: var(--danger-foreground);
}

.field {
  margin-block-end: 1rem;
}

.field > label,
form > label {
  margin-block-end: 0.3rem;
  color: var(--foreground);
  font-weight: 500;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.field-head label {
  margin-block-end: 0.3rem;
}

.field-note {
  margin: 0.45rem 0 1rem;
  color: var(--muted-foreground);
  font-size: 0.78rem;
}

.link-button {
  padding: 0;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.link-button:hover {
  background: none;
  color: color-mix(in srgb, var(--primary) 78%, var(--foreground));
  transform: none;
}

.link-button:disabled {
  cursor: default;
  opacity: 0.5;
}

.btn-checkin {
  width: 100%;
  min-height: 4rem;
  margin-block-start: 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.015em;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.danger-link,
.link-button.danger-link {
  color: var(--danger);
}

.message-body {
  margin-block-start: 0.35rem;
  line-height: 1.65;
}

.message-body > :first-child {
  margin-block-start: 0;
}

.message-body > :last-child {
  margin-block-end: 0;
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4,
.message-body h5,
.message-body h6 {
  margin: 1.3em 0 0.4em;
  font-size: 1.05rem;
}

.message-body ul,
.message-body ol {
  padding-inline-start: 1.4em;
  margin-block-end: 0.9em;
}

.message-body li > p {
  margin-block-end: 0;
}

.message-body blockquote {
  padding-inline-start: 0.75rem;
  border-inline-start-width: 3px;
  font-style: normal;
}

.message-body pre code {
  padding: 0;
  background: none;
}

.contact-list,
.attachment-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.contact-list li,
.attachment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.7rem;
  border-bottom: 1px solid var(--border);
}

.contact-list li:last-child,
.attachment-list li:last-child {
  border-bottom: 0;
}

.contact-list li > span,
.attachment-meta {
  min-width: 0;
  flex: 1;
}

.attachment-name {
  display: block;
  overflow-wrap: anywhere;
}

.attachment-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.75rem;
}

.upload-form {
  margin-block-start: 1rem;
  padding-block-start: 1rem;
  border-top: 1px solid var(--border);
}

.message-title {
  display: block;
  font-weight: 500;
}

.message-excerpt {
  display: block;
  max-width: 48ch;
  margin-block-start: 0.15rem;
  color: var(--muted-foreground);
  font-size: 0.78rem;
  line-height: 1.45;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.check-fieldset {
  min-width: 0;
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

.check-fieldset legend {
  margin-block-end: 0.35rem;
  padding: 0;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
}

.check-list {
  overflow: hidden;
  border: 1px solid var(--input);
  border-radius: var(--radius-medium);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--foreground);
  cursor: pointer;
  font-weight: 400;
}

.check-row:last-child {
  border-bottom: 0;
}

.check-row input {
  width: auto;
  margin-block-start: 0.2rem;
}

.check-row span {
  display: block;
}

.check-row .hint {
  display: block;
}

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

.table th {
  padding-inline: 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.table td {
  padding-inline: 0.65rem;
  vertical-align: top;
  font-variant-numeric: tabular-nums;
}

.table th:first-child,
.table td:first-child {
  padding-inline-start: 0;
}

.table th:last-child,
.table td:last-child {
  padding-inline-end: 0;
}

.actions-cell {
  text-align: end;
  white-space: nowrap;
}

.cell-primary,
.cell-secondary,
.table-cell {
  display: block;
  min-width: 0;
}

.cell-primary {
  font-weight: 500;
}

.cell-secondary {
  margin-block-start: 0.1rem;
  color: var(--muted-foreground);
  font-size: 0.78rem;
}

.cell-date {
  white-space: nowrap;
}

.cell-email {
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted-foreground);
}

.reminders-table {
  table-layout: fixed;
}

.reminders-table th:nth-child(1) { width: 29%; }
.reminders-table th:nth-child(2) { width: 17%; }
.reminders-table th:nth-child(3) { width: 22%; }
.reminders-table th:nth-child(4) { width: 13%; }
.reminders-table th:nth-child(5) { width: 19%; }

.messages-table {
  table-layout: fixed;
}

.messages-table th:nth-child(1) { width: 13%; }
.messages-table th:nth-child(2) { width: 55%; }
.messages-table th:nth-child(3) { width: 17%; }
.messages-table th:nth-child(4) { width: 15%; }

@media (max-width: 760px) {
  :root {
    --container-pad: 0.75rem;
  }

  .site-header .container {
    gap: 0.6rem;
    padding-block: 0.65rem;
  }

  .site-title {
    flex: 1 1 auto;
  }

  .nav-links {
    order: 3;
    width: 100%;
    overflow: visible;
    padding-block-end: 0.1rem;
    flex-wrap: wrap;
    gap: 0.3rem 0.75rem;
    font-size: 0.8rem;
  }

  .nav-links a {
    white-space: nowrap;
  }

  .header-actions {
    gap: 0.55rem;
  }

  main.container {
    padding-block-start: 1.25rem;
  }

  .card {
    padding: 1.1rem;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

  .hero-stat {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    align-items: baseline;
    gap: 0.25rem 0.75rem;
  }

  .hero-stat .label {
    margin: 0;
  }

  .hero-stat .hint {
    grid-column: 2;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tr {
    padding-block: 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .responsive-table tr:last-child {
    border-bottom: 0;
  }

  .responsive-table td {
    display: grid;
    grid-template-columns: 6.25rem minmax(0, 1fr);
    gap: 0.75rem;
    padding: 0.3rem 0;
    border: 0;
    text-align: start;
    white-space: normal;
  }

  .responsive-table td::before {
    grid-column: 1;
    content: attr(data-label);
    padding-block-start: 0.1rem;
    color: var(--muted-foreground);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.055em;
    text-transform: uppercase;
  }

  .responsive-table .table-cell {
    grid-column: 2;
    grid-row: 1;
  }

  .responsive-table .actions-cell {
    padding-block-start: 0.5rem;
    text-align: start;
  }

  .responsive-table .row-actions {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .responsive-table .message-excerpt {
    max-width: none;
  }

  .cell-date {
    white-space: normal;
  }

  .contact-list li,
  .attachment-list li {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.45rem;
  }

  .attachment-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 460px) {
  .button-row .button {
    flex: 1 1 auto;
  }
}
