:root {
  color-scheme: light;
  --bg: #e9eff0;
  --bg-deep: #dce7e9;
  --card: #fbfcfa;
  --card-strong: #ffffff;
  --text: #172c35;
  --muted: #60747b;
  --line: #cbdadd;
  --line-strong: #9db7bd;
  --primary: #0d626d;
  --primary-dark: #084951;
  --primary-ink: #ffffff;
  --primary-soft: #e2f0f1;
  --accent: #d89938;
  --accent-soft: #fff0d4;
  --accent-ink: #67491f;
  --danger: #a23f43;
  --success: #236f59;
  --success-bg: #e0f2eb;
  --error-bg: #fbe9e8;
  --shadow: 0 18px 45px rgba(18, 50, 61, .11), 0 2px 5px rgba(18, 50, 61, .06);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

* { box-sizing: border-box; }

html { min-width: 320px; scroll-behavior: smooth; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: var(--bg);
  background-image: linear-gradient(135deg, rgba(255, 255, 255, .7), transparent 42%), linear-gradient(rgba(13, 98, 109, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(13, 98, 109, .035) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; }

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: not-allowed; opacity: .45; }

button, input, select, textarea, a { transition: border-color .16s ease, background-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

a { color: var(--primary); }

.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;
}

.shell { width: min(1260px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 72px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }

.login-card {
  position: relative;
  width: min(430px, 100%);
  margin: 10vh auto 0;
  overflow: hidden;
  padding: clamp(25px, 5vw, 40px);
  border-top: 3px solid var(--primary);
}

.login-card::before {
  position: absolute;
  top: -74px;
  right: -58px;
  width: 220px;
  height: 220px;
  border: 1px solid rgba(13, 98, 109, .14);
  border-radius: 50%;
  box-shadow: 0 0 0 22px rgba(13, 98, 109, .035), 0 0 0 44px rgba(13, 98, 109, .025);
  content: "";
  pointer-events: none;
}

.login-card > * { position: relative; }
.login-card > .muted { margin-bottom: 26px; }
.login-card .primary { width: 100%; margin-top: 6px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  margin: 0 0 18px;
  padding: 10px 14px 10px 11px;
  overflow-wrap: anywhere;
  border-radius: 8px;
  background: var(--text);
  color: var(--card);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(.92rem, 3vw, 1rem);
  font-weight: 750;
  letter-spacing: .015em;
  line-height: 1.2;
}

.brand-mark::before {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(216, 152, 56, .18);
  content: "";
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { color: var(--text); letter-spacing: -.025em; }
h1 { margin-bottom: 6px; font-size: clamp(1.55rem, 2.5vw, 2.15rem); line-height: 1.08; }
h2 { margin-bottom: 5px; font-size: clamp(1.22rem, 2vw, 1.4rem); line-height: 1.15; }
h3 { margin-bottom: 5px; font-size: 1rem; line-height: 1.25; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

.stack, .compose-form { display: grid; gap: 10px; }

label { display: grid; gap: 6px; color: var(--text); font-size: .84rem; font-weight: 700; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--card-strong);
  color: var(--text);
  padding: 11px 12px;
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 98, 109, .13); }
textarea { min-height: 180px; resize: vertical; line-height: 1.55; }

button {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 10px 15px;
  font-weight: 750;
  line-height: 1.25;
}

button:active:not(:disabled) { transform: translateY(1px); }
.primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 3px 0 var(--primary-dark); }
.primary:hover { background: var(--primary-dark); }
.secondary { border-color: var(--line); background: transparent; color: var(--text); }
.secondary:hover { border-color: var(--line-strong); background: var(--bg-deep); }
.link-button, .table-link { border: 0; border-radius: 0; padding: 0; background: transparent; color: var(--primary); font-weight: 750; text-align: left; }
.link-button:hover, .table-link:hover { color: var(--primary-dark); text-decoration: underline; }

.language-picker { display: flex; align-items: center; justify-content: space-between; margin-top: 23px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); }
.language-picker select { width: auto; min-width: 100px; padding: 7px 9px; }
.language-picker.compact { margin: 0; padding: 0; border: 0; gap: 7px; }
.language-picker.compact span { display: none; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 20px; padding: 0 4px 20px; border-bottom: 1px solid var(--line); }
.topbar > div:first-child { min-width: 0; }
.topbar h1 { margin-bottom: 0; }
.topbar-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
.eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; color: var(--primary); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; font-weight: 750; letter-spacing: .05em; }
.eyebrow::before { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(216, 152, 56, .15); content: ""; }
.user-badge { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .78rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-badge::before { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: var(--success); content: ""; }

.tabs { display: flex; gap: 4px; margin-bottom: 15px; border-bottom: 1px solid var(--line); }
.tab { position: relative; border-radius: 7px 7px 0 0; background: transparent; color: var(--muted); }
.tab:hover { background: var(--bg-deep); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab.active::after { position: absolute; right: 8px; bottom: -1px; left: 8px; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary); content: ""; }

.view { padding: clamp(20px, 3vw, 30px); }
.view.card { border-top: 2px solid var(--line-strong); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 23px; }
.section-heading h2 { display: flex; align-items: center; gap: 10px; }
.section-heading h2::before { flex: 0 0 auto; width: 24px; height: 3px; border-radius: 2px; background: var(--accent); content: ""; }
.section-heading .muted { margin-bottom: 0; }
.section-heading .link-button { margin-bottom: 12px; }

.banner { margin: 0 0 15px; padding: 11px 14px; border: 1px solid transparent; border-radius: 7px; }
.error { color: var(--danger); font-size: .88rem; }
.banner.error, .error.banner { border-color: rgba(162, 63, 67, .2); background: var(--error-bg); }
.notice { border-color: rgba(35, 111, 89, .2); color: var(--success); background: var(--success-bg); font-size: .88rem; }

.filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(145px, .3fr) auto; align-items: end; gap: 12px; margin-bottom: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.filter-submit { min-height: 43px; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--card-strong); }
table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 12px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: var(--bg); color: var(--muted); font-size: .76rem; font-weight: 750; letter-spacing: .02em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color .16s ease; }
tbody tr:hover { background: var(--primary-soft); }
tbody td:first-child, tbody td:nth-child(2), tbody td:nth-child(3) { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.empty { margin-top: 14px; padding: 35px 10px; border: 1px dashed var(--line-strong); border-radius: 9px; color: var(--muted); text-align: center; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 20px; color: var(--muted); font-size: .88rem; }
.pagination button { min-width: 92px; }

.message-meta { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0 0 22px; padding: 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.message-meta dt { color: var(--muted); font-weight: 750; }
.message-meta dd { margin: 0; overflow-wrap: anywhere; }
.routing { margin-bottom: 16px; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; overflow-wrap: anywhere; }
.routing strong { display: block; margin-bottom: 5px; font-family: inherit; }
.message-body { min-height: 160px; margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: 9px; background: var(--card-strong); font: .92rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.compose-form { max-width: 940px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 5px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 17px; }
.file-card { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--card-strong); }
.file-card:hover { border-color: var(--line-strong); box-shadow: 0 8px 22px rgba(18, 50, 61, .08); transform: translateY(-2px); }
.file-card > img { display: block; width: 100%; height: 180px; border-bottom: 1px solid var(--line); object-fit: cover; background: var(--bg-deep); }
.file-icon { display: grid; place-items: center; height: 180px; border-bottom: 1px solid var(--line); background-color: var(--primary-soft); background-image: linear-gradient(rgba(13, 98, 109, .08) 1px, transparent 1px), linear-gradient(90deg, rgba(13, 98, 109, .08) 1px, transparent 1px); background-size: 24px 24px; color: var(--primary); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 2rem; font-weight: 800; }
.file-card-content { flex: 1; padding: 14px; }
.file-card-content p { margin: 4px 0 9px; overflow-wrap: anywhere; }

@media (max-width: 720px) {
  .shell { width: min(100% - 20px, 1260px); padding-top: 15px; }
  .login-card, .view { padding: 20px; }
  .login-card { margin-top: 6vh; }
  .topbar { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .user-badge { max-width: 180px; }
  .tabs { overflow-x: auto; }
  .tab { flex: 1; min-width: max-content; white-space: nowrap; }
  .filters { grid-template-columns: 1fr; align-items: stretch; }
  .filter-submit { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .section-heading { align-items: stretch; flex-direction: column; gap: 12px; }
  .section-heading > button { align-self: flex-start; }
}

@media (max-width: 440px) {
  .shell { width: min(100% - 16px, 1260px); }
  .view, .login-card { padding: 17px; }
  .topbar-actions { align-items: flex-start; flex-direction: column; }
  .language-picker.compact { align-self: flex-end; }
  .form-actions { flex-direction: column; }
  .form-actions button { width: 100%; }
  .message-meta { grid-template-columns: 1fr; gap: 3px; }
  .message-meta dd { margin-bottom: 8px; }
  .pagination { gap: 8px; justify-content: space-between; }
  .pagination button { min-width: 0; padding-inline: 10px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1a1d;
    --bg-deep: #14272c;
    --card: #17262a;
    --card-strong: #1b2d32;
    --text: #e7f0ef;
    --muted: #9cb0b3;
    --line: #2c454a;
    --line-strong: #4b6970;
    --primary: #5ec2c8;
    --primary-dark: #8ed9dc;
    --primary-ink: #082225;
    --primary-soft: #1c3c41;
    --accent: #e3ab4f;
    --accent-soft: #40341f;
    --accent-ink: #f1c978;
    --danger: #f08b8d;
    --success: #77d1ae;
    --success-bg: #183a31;
    --error-bg: #422528;
    --shadow: 0 18px 45px rgba(0, 0, 0, .24), 0 2px 5px rgba(0, 0, 0, .18);
  }

  body {
    background-image: linear-gradient(135deg, rgba(94, 194, 200, .06), transparent 42%), linear-gradient(rgba(94, 194, 200, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(94, 194, 200, .035) 1px, transparent 1px);
  }

  .login-card::before { border-color: rgba(94, 194, 200, .14); box-shadow: 0 0 0 22px rgba(94, 194, 200, .035), 0 0 0 44px rgba(94, 194, 200, .025); }
  input, select, textarea { border-color: var(--line); }
  .secondary:hover, tbody tr:hover { background: var(--primary-soft); }
  .table-wrap { background: var(--card-strong); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .file-card:hover, button:active:not(:disabled) { transform: none; }
}
