/*
 * Shared platform base styles.
 * Served by Caddy at /shared/styles/base.css on every subdomain.
 * Contains design tokens, dark mode, form controls and layout primitives.
 * App-specific styles belong in the app's own stylesheet.
 */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #f3f4f6;
  --text: #1f2937;
  --muted: #57606a;
  --border: #d6dce5;
  --accent: #2d6cdf;
  --accent-soft: #eef4ff;
  --ok: #159947;
  --danger: #c1323f;
  --warning: #b87f10;
  --shadow: 0 10px 26px rgba(16, 24, 40, 0.08);
  --button-bg: #f3f4f6;
  --input-bg: #ffffff;
}

body.dark-mode {
  --bg: #2f2f2f;
  --surface: #3a3a3a;
  --surface-alt: #404040;
  --text: #f3f4f6;
  --muted: #c7c9cf;
  --border: #4a4a4a;
  --accent: #7aa2ff;
  --accent-soft: #434343;
  --ok: #55d08b;
  --danger: #ff7d88;
  --warning: #f2c86d;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  --button-bg: #404040;
  --input-bg: #383838;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  padding: 10px 12px;
  resize: vertical;
  min-height: 42px;
}

button {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--button-bg);
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select {
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  padding: 10px 12px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23808a96' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px 8px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

label {
  color: var(--muted);
  font-size: 14px;
}

.app-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
}

.app-nav a {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--surface-alt);
}

.app-nav a.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.app-nav-context {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.logout-top {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--button-bg);
}

.theme-toggle {
  position: relative;
  width: 58px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  color: transparent;
  font-size: 0;
  overflow: hidden;
  background: var(--surface-alt);
}

.theme-toggle::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.theme-toggle::after {
  content: "🌞";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  transition: transform 0.2s ease;
}

.theme-toggle[aria-checked="true"]::before,
.theme-toggle[aria-checked="true"]::after {
  transform: translateX(26px);
}

.theme-toggle[aria-checked="true"]::after {
  content: "🌚";
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 84px 16px 26px;
}

.app-shell--narrow {
  max-width: 760px;
}

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

.page-title {
  font-size: clamp(24px, 4vw, 36px);
  letter-spacing: 0.2px;
  flex: 0 1 auto;
  min-width: 0;
}

.status-line {
  color: var(--muted);
  font-size: 14px;
  margin-left: auto;
  flex: 1 1 320px;
  min-width: min(100%, 280px);
  align-self: flex-end;
  text-align: right;
  overflow-wrap: anywhere;
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.meta-pill {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
  gap: 16px;
}


.stack {
  display: grid;
  gap: 16px;
}

.card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h3 {
  margin-bottom: 10px;
}

.section-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.section-hint {
  color: var(--muted);
  font-size: 14px;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section-top-gap {
  margin-top: 10px;
}

.profile-form {
  display: grid;
  gap: 8px;
}

.profile-disclosure {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-alt);
}

.profile-disclosure summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.profile-disclosure[open] summary {
  margin-bottom: 10px;
}

.upload-dropzone {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-dropzone:hover,
.upload-dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.upload-dropzone-title {
  font-weight: 600;
}

.upload-dropzone-subtitle,
.upload-selected-file {
  color: var(--muted);
  font-size: 14px;
}

.profile-avatar-wrap {
  margin-bottom: 10px;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  display: block;
}

.profile-avatar-clickable {
  cursor: zoom-in;
}

.profile-avatar-modal {
  position: fixed;
  inset: 0;
  z-index: 240;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.78);
  padding: 20px;
}

.profile-avatar-modal[hidden] {
  display: none;
}

.profile-avatar-modal-image {
  width: min(88vw, 640px);
  height: min(88vh, 640px);
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.profile-avatar-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
  padding: 0;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.45);
}

body.login-page {
  min-height: 100vh;
}

.login-shell {
  max-width: 560px;
  margin: 80px auto 24px;
  padding: 0 16px;
}

#login-form,
#register-form {
  display: grid;
  gap: 10px;
}

#login-form[hidden],
#register-form[hidden],
.auth-form[hidden] {
  display: none;
}

.login-grid {
  display: grid;
  gap: 16px;
}

.auth-shell {
  display: grid;
  gap: 16px;
}

.auth-card {
  display: grid;
  gap: 14px;
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  padding-right: 64px;
}

.password-toggle-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.password-toggle-btn:hover,
.password-toggle-btn:focus-visible {
  border: 0;
  background: transparent;
}

.password-toggle-btn::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: 0 auto;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M2.2 12s3.2-6 9.8-6s9.8 6 9.8 6s-3.2 6-9.8 6S2.2 12 2.2 12z' fill='none' stroke='%23808a96' stroke-width='1.8'/%3E%3Ccircle cx='12' cy='12' r='3' fill='none' stroke='%23808a96' stroke-width='1.8'/%3E%3C/svg%3E");
}

.password-toggle-btn.is-visible::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M2.2 12s3.2-6 9.8-6s9.8 6 9.8 6s-3.2 6-9.8 6S2.2 12 2.2 12z' fill='none' stroke='%23808a96' stroke-width='1.8'/%3E%3Ccircle cx='12' cy='12' r='3' fill='none' stroke='%23808a96' stroke-width='1.8'/%3E%3Cpath d='M4 20L20 4' fill='none' stroke='%23808a96' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
}

.auth-mode-tabs button {
  min-width: 120px;
}

body.login-page .theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 120;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.app-tile {
  display: grid;
  gap: 8px;
  align-content: start;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.app-tile:hover,
.app-tile:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.app-tile-icon {
  font-size: 34px;
  line-height: 1;
}

.app-tile-title {
  font-size: 20px;
  font-weight: 600;
}

.app-tile-description {
  color: var(--muted);
  font-size: 14px;
}

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

@media (max-width: 720px) {
  .app-shell {
    padding-top: 92px;
  }

  .app-nav-context {
    display: none;
  }

  .page-title {
    font-size: 24px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-line {
    margin-left: 0;
    width: 100%;
    text-align: left;
  }
}

/* ---------------------------------------------------------------------------
 * Shared components. Generic building blocks for every app; app-specific
 * styling stays in the app's own stylesheet.
 * ------------------------------------------------------------------------- */

:root {
  --radius: 12px;
  --tap-size: 44px;
  --on-accent: #ffffff;
}

body.dark-mode {
  --on-accent: #10172a;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.button-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button-quiet:hover {
  color: var(--text);
}

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

.button-block {
  width: 100%;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--button-bg);
  color: var(--text);
  text-decoration: none;
}

.button-link:hover {
  border-color: var(--accent);
}

.button-link.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.badge--accent {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.badge--ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge--warning {
  border-color: var(--warning);
  color: var(--warning);
}

.badge--danger {
  border-color: var(--danger);
  color: var(--danger);
}

.field {
  display: grid;
  gap: 6px;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap-size);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

a.list-item {
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

a.list-item:hover {
  border-color: var(--accent);
}

.list-item-main {
  display: grid;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.list-item-meta {
  color: var(--muted);
  font-size: 13px;
}

.list-item-aside {
  display: grid;
  justify-items: end;
  gap: 4px;
  flex: 0 0 auto;
  text-align: right;
}

.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.avatar--fallback {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.empty-state {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 50%, var(--surface-alt) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Native <dialog>: centered on large screens, bottom sheet on phones. */
.sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.sheet-title {
  font-size: 18px;
}

.sheet-body {
  padding: 12px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-close {
  width: var(--tap-size);
  height: var(--tap-size);
  padding: 0;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
}

/* Shown at the top, so it never covers a sticky action bar at the bottom. */
.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  z-index: 300;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  font-weight: 600;
}

.toast--error {
  background: var(--danger);
  color: #ffffff;
}

/* Main action that stays reachable at the bottom of the screen on phones. */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}

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

.data-table th,
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.data-table .is-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tr.is-highlighted td {
  background: var(--accent-soft);
}

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

@media (max-width: 720px) {
  .sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: 88vh;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Comfortable touch targets for the shared components (opt-in, so existing
   compact controls of other apps keep their size). */
@media (pointer: coarse) {
  .button-primary,
  .button-quiet,
  .button-link,
  .field input,
  .field select,
  .inline-field select {
    min-height: var(--tap-size);
  }
}

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

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 400;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.card-title {
  font-size: 18px;
}

.card > .card-title {
  margin-bottom: 10px;
}

.card-head .card-title {
  margin: 0;
}

.section-gap {
  margin-top: 16px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 14px;
}

.chip .avatar {
  width: 26px;
  height: 26px;
}

.chip.is-me {
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 560px) {
  .hide-narrow {
    display: none;
  }
}
