:root {
  --bg: #f4f6f5;
  --bg-alt: #e9eeeb;
  --surface: #fff;
  --surface-strong: #fff;
  --surface-soft: #eef3f0;
  --text: #172721;
  --muted: #586c62;
  --border: #d6e1da;
  --accent: #18764d;
  --accent-strong: #11613e;
  --accent-soft: #e4f3eb;
  --teal: #16786b;
  --gold: #a3740d;
  --tab-shell-bg: var(--surface);
  --tab-item-bg: var(--surface);
  --tab-item-active-bg: var(--surface-soft);
}
:root[data-theme="dark"] {
  --bg: #141817;
  --bg-alt: #1c2220;
  --surface: #1b211f;
  --surface-strong: #202824;
  --surface-soft: #27322c;
  --text: #f1f5f2;
  --muted: #a0b1a6;
  --border: #313f36;
  --accent: #79d8a0;
  --accent-strong: #9ee2b9;
  --accent-soft: #223d2e;
  --teal: #87cec6;
  --gold: #f6cf59;
  --tab-shell-bg: var(--surface);
  --tab-item-bg: var(--surface);
  --tab-item-active-bg: var(--surface-soft);
}
html { font-size: 16px; scroll-padding-top: 90px; }
body.web-app { background: var(--bg); font-size: 14px; line-height: 1.5; }
.web-app * { letter-spacing: 0; }
[hidden], .web-app .hidden { display: none !important; }
.web-app h1, .web-app h2, .web-app h3, .web-app p { margin-top: 0; overflow-wrap: anywhere; }
.web-app h1 { font-size: 26px; line-height: 1.25; }
.web-app h2 { font-size: 20px; line-height: 1.35; }
.web-app h3 { font-size: 16px; line-height: 1.4; }
.web-app button, .web-app input, .web-app textarea, .web-app select { font: inherit; }
.web-app input, .web-app select, .web-app textarea {
  min-width: 0; max-width: 100%; font-size: 16px; border-radius: 6px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
}
.web-app input:not([type="checkbox"]):not([type="radio"]), .web-app select { min-height: 44px; }
.web-app label { color: var(--text); }
.web-app button, .web-app a { -webkit-tap-highlight-color: transparent; }
.web-app button:focus-visible, .web-app a:focus-visible, .web-app input:focus-visible,
.web-app select:focus-visible, .web-app textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.web-app button:disabled { opacity: .55; cursor: wait; }
.web-app .primary-button {
  color: var(--bg); background: var(--accent); border: 1px solid var(--accent);
  box-shadow: none; border-radius: 6px; min-height: 42px; font-weight: 700;
}
.web-app .primary-button:hover { background: var(--accent-strong); transform: none; }
.web-app .ghost-button, .web-app .theme-toggle, .web-app .tiny-button, .web-app .icon-button {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: none; min-height: 38px;
}
.web-app .theme-toggle, .web-app .ghost-button { padding: 8px 12px; }
.web-app .reader-close-button {
  background: #151c29; color: #fff; border-color: #60718a; padding: 0; font-size: 26px;
}
.web-app .text-link { color: var(--accent); text-decoration: none; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 1000; background: var(--surface); padding: 12px; }
.skip-link:focus { top: 8px; }
.app-header {
  height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 30;
}
.app-header .brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.app-header .brand img { object-fit: contain; border-radius: 6px; }
.app-header .brand strong { font-size: 18px; }
.app-header-actions { display: flex; align-items: center; gap: 8px; }
.app-status { padding: 10px 24px; background: var(--accent-soft); color: var(--text); text-align: center; }
.app-status button { margin-left: 10px; }
.app-downloads { width: min(100% - 40px, 1000px); margin: 36px auto; background: none; border: 0; box-shadow: none; }
.web-app .download-card { border-radius: 8px; }
.web-app .auth-page {
  position: static; min-height: calc(100vh - 72px); display: grid; align-items: center;
  padding: 40px 20px; background: var(--bg);
}
.web-app .auth-page .auth-card {
  position: static; width: min(100%, 460px); max-height: none; overflow: visible;
  padding: 0; margin: auto; border: 0; border-radius: 0;
  box-shadow: none; background: transparent; backdrop-filter: none; color: var(--text); gap: 24px;
}
.web-app .auth-page[data-auth-view="signup"] .auth-card { width: min(100%, 620px); }
.web-app .auth-head { display: grid; justify-items: center; gap: 10px; }
.web-app .auth-logo { object-fit: contain; border-radius: 8px; }
.web-app .auth-brand { color: var(--gold); font-size: 38px; font-weight: 900; line-height: 1.1; }
.web-app .auth-page .auth-welcome { display: block; color: var(--text); font-size: 18px; font-weight: 600; margin: 0 0 10px; }
.web-app .auth-head h1 { font-size: 22px; margin: 0; }
.web-app .auth-switcher { border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.web-app .auth-page .switch-tab { color: var(--muted); padding: 8px 10px; border-radius: 4px; min-height: 40px; }
.web-app .auth-page .switch-tab.active { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.web-app .auth-page .switch-tab[data-auth-view="reset"] { display: none; }
.web-app .auth-page .auth-form { gap: 18px; }
.web-app .auth-page .auth-form input, .web-app .auth-page .auth-form select {
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 11px 12px;
}
.web-app .auth-page .auth-form select option { color: var(--text); background: var(--surface); }
.web-app .auth-page .auth-field::after { display: none; }
.web-app .auth-page .auth-field-password input { padding-right: 48px; }
.web-app .auth-page .password-toggle { color: var(--muted); background: none; right: 8px; bottom: 5px; }
.web-app .auth-page .auth-card .primary-button { background: var(--accent); color: var(--bg); border-radius: 6px; box-shadow: none; }
.web-app .auth-page .auth-inline-button, .web-app .auth-page .auth-check { color: var(--muted); }
.web-app .auth-page .auth-flash { background: var(--surface); color: var(--text); border-color: var(--border); border-radius: 6px; }
.web-app .modal-card { background: var(--surface); color: var(--text); border-radius: 8px; max-height: calc(100vh - 40px); overflow: auto; }
.web-app .site-shell.space-shell { width: 100%; max-width: none; padding: 0; }
.workspace-content { margin-left: 218px; padding: 28px 32px 48px; max-width: 1600px; }
.web-app .portal-shell--standalone { margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.web-app .portal-topbar { padding: 0 0 24px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none; background: none; margin: 0 0 24px; }
.web-app .portal-topbar p { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.web-app .portal-tabs {
  position: fixed; left: 0; top: 72px; bottom: 0; width: 218px; margin: 0;
  display: flex; flex-direction: column; padding: 24px 14px; gap: 10px;
  border: 0; border-right: 1px solid var(--border); border-radius: 0; background: var(--surface); box-shadow: none;
  backdrop-filter: none; overflow: visible; z-index: 25;
}
.web-app .portal-tabs button {
  min-height: 54px; padding: 12px; justify-content: start; grid-template-columns: 28px 1fr auto;
  text-align: left; text-transform: none; color: var(--muted); background: transparent; border-color: transparent;
}
.web-app .portal-tabs button:hover, .web-app .portal-tabs button.active {
  color: var(--tab-neon); background: var(--surface-soft); box-shadow: none; transform: none; border-color: var(--border);
}
.web-app .portal-tabs button .tab-label { font-size: 14px; font-weight: 600; }
.web-app .tab-icon { background: transparent; }
.web-app .tab-badge { background: var(--surface-soft); color: var(--text); font-size: 11px; }
.web-app .portal-grid { grid-template-columns: minmax(200px, .3fr) minmax(0, 1fr); gap: 24px; }
.web-app .portal-grid--feed { grid-template-columns: 1fr 1fr; }
.web-app .portal-grid--feed > .profile-card { grid-column: 1 / -1; padding: 0 0 24px; border-bottom: 1px solid var(--border); }
.web-app .sidebar-card { padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; min-width: 0; }
.web-app .profile-meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.web-app .card-head { margin-bottom: 16px; }
.web-app .notification-item { padding: 14px 0; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none; }
.web-app .notification-item p { margin: 6px 0 0; color: var(--muted); }
.web-app .notification-item.is-unread { border-left: 2px solid var(--accent); padding-left: 12px; }
.web-app .portal-toolbar { gap: 12px; margin: 0 0 18px; }
.web-app .toolbar-options { padding: 16px 0; border: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; background: none; }
.web-app .toolbar-status { border-radius: 6px; background: var(--surface-soft); }
.web-app .toolbar-filters { grid-template-columns: minmax(0, 1fr) minmax(130px, .6fr) auto; }
.web-app .material-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.web-app .material-card { padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: none; min-width: 0; }
.web-app .material-card p { font-size: 14px; }
.web-app .material-meta { color: var(--muted); font-size: 12px; }
.web-app .empty-state { background: transparent; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); padding: 28px 16px; }
.web-app .space-form { max-width: 760px; margin: 0; padding: 0; border: 0; background: none; box-shadow: none; }
.web-app .detail-box { background: none; border: 0; padding: 0; }
.web-app .chat-web-grid { grid-template-columns: minmax(180px, .32fr) minmax(0, 1fr); gap: 24px; }
.web-app .chat-web-thread { min-height: 380px; height: calc(100vh - 260px); display: flex; flex-direction: column; }
.web-app .chat-message-list { flex: 1; min-height: 0; overflow-y: auto; }
.web-app .chat-compose { display: flex; gap: 8px; padding: 12px 0 0; background: var(--bg); }
.web-app .chat-compose input { flex: 1; }
.web-app .chat-compose button { flex-shrink: 0; }
.workspace-error { margin-bottom: 18px; display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 6px; }
.profile-settings { max-width: 720px; }
.profile-settings summary { cursor: pointer; padding: 16px 0; font-weight: 600; border-bottom: 1px solid var(--border); margin: 20px 0; }
.offline-page { max-width: 460px; padding: 24px; margin: 15vh auto; text-align: center; }
.offline-page p { color: var(--muted); }
@media (max-width: 1000px) {
  .workspace-content { margin-left: 190px; padding: 24px; }
  .web-app .portal-tabs { width: 190px; }
  .web-app .portal-grid { grid-template-columns: 1fr; }
  .web-app .portal-grid--feed { grid-template-columns: 1fr 1fr; }
  .web-app .portal-sidebar { display: none; }
}
@media (max-width: 720px) {
  html { font-size: 16px; }
  .app-header { height: auto; min-height: 64px; padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .app-header .brand { gap: 7px; }
  .app-header .brand strong { font-size: 16px; }
  .app-header .brand img { width: 30px; height: 30px; }
  .app-header-actions { gap: 5px; }
  .app-header-actions .ghost-button, .app-header-actions .theme-toggle { padding: 7px 8px; font-size: 12px; min-height: 38px; }
  .web-app .auth-page { min-height: calc(100vh - 64px); padding: 32px 20px; }
  .web-app .auth-page .auth-card, .web-app .auth-page[data-auth-view="login"] .auth-card, .web-app .auth-page[data-auth-view="reset"] .auth-card { width: 100%; }
  .web-app .auth-brand { font-size: 34px; }
  .web-app .auth-page .auth-welcome { font-size: 16px; }
  .web-app .auth-page .form-grid { grid-template-columns: 1fr; }
  .workspace-content { margin-left: 0; padding: 20px 16px calc(100px + env(safe-area-inset-bottom)); }
  .web-app .portal-topbar { padding-bottom: 18px; margin-bottom: 20px; }
  .web-app .portal-tabs {
    top: auto; bottom: 0; width: 100%; height: auto; min-height: 74px;
    display: flex; flex-direction: row; gap: 4px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border: 0; border-top: 1px solid var(--border); border-radius: 0;
  }
  .web-app .portal-tabs button {
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
    gap: 2px; min-height: 60px; padding: 5px 2px;
  }
  .web-app .portal-tabs button .tab-label { font-size: 11px; }
  .web-app .tab-icon { height: 25px; width: 25px; }
  .web-app .tab-badge { position: absolute; top: 3px; right: 8px; height: 16px; min-width: 16px; }
  .web-app .portal-grid--feed, .web-app .material-grid { grid-template-columns: 1fr; }
  .web-app .toolbar-filters { grid-template-columns: 1fr; }
  .web-app .portal-toolbar { flex-direction: row; align-items: center; }
  .web-app .material-card { padding: 16px; }
  .web-app .chat-web-grid { grid-template-columns: 1fr; gap: 20px; }
  .web-app .chat-space-list { max-height: 150px; overflow-y: auto; }
  .web-app .chat-web-thread { height: calc(var(--app-height, 100vh) - 230px); min-height: 260px; }
  .web-app[data-active-tab="chat"] .chat-web-thread { height: calc(var(--app-height, 100vh) - 490px); }
  .web-app .chat-compose { position: sticky; bottom: 76px; }
  .keyboard-open .portal-tabs { display: none; }
  .keyboard-open .chat-compose { bottom: 0; }
  .web-app .reader-window { width: 100%; height: 100%; max-height: none; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .web-app *, .web-app *::before, .web-app *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
