/* Phase 1 design tokens. Override this layer when adding another color scheme. */
:root {
  --bg: #f6f7fa;
  --surface: #ffffff;
  --surface-muted: #f1f3f7;
  --text-primary: #2c3342;
  --text-secondary: #737b8b;
  --border: #e3e7ef;
  --accent: #5363c7;
  --accent-soft: #edf0ff;
  --success: #27805e;
  --warning: #a16b17;
  --danger: #c04c53;
  --radius-sm: 10px;
  --radius-md: 12px;
  --shadow-sm: 0 2px 8px rgb(34 44 70 / 3%);
  --app-sidebar-width: 232px;
}
body.app-shell { margin: 0; padding: 0; background: var(--bg); color: var(--text-primary); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; line-height: 1.5; }
.app-sidebar, .app-sidebar *, .app-mobile-header, .app-mobile-header *, .app-drawer, .app-drawer *, .app-guest-header, .app-guest-header *, .app-flashes, .app-flashes * { box-sizing: border-box; }
.app-icon { display: inline-block; width: 22px; height: 22px; flex: 0 0 auto; vertical-align: middle; }
.app-brand { display: flex; flex-direction: column; gap: 3px; width: fit-content; color: var(--text-primary); text-decoration: none; line-height: 1.4; }
.app-brand > strong { font-size: 25px; font-weight: 700; letter-spacing: -.8px; }
.app-brand > span { color: var(--text-secondary); font-size: 11px; letter-spacing: .05em; }
.app-brand-dot { color: var(--accent); }
.app-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 100; display: flex; flex-direction: column; width: var(--app-sidebar-width); padding: 34px 18px 20px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.app-sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 30px 8px; }
.app-sidebar-header > .app-brand { min-width: 0; }
.app-sidebar-toggle[hidden] { display: none; }
.app-sidebar-main { display: grid; gap: 5px; }
.app-nav-link { display: flex; align-items: center; gap: 13px; min-height: 44px; padding: 11px 14px; border-radius: var(--radius-sm); color: var(--text-secondary); text-decoration: none; font-size: 14px; font-weight: 500; line-height: 1.5; transition: background-color .15s, color .15s; }
.app-nav-link .app-icon { width: 20px; height: 20px; }
.app-nav-link:hover { background: var(--surface-muted); color: var(--text-primary); }
.app-nav-link.app-nav-link--active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.app-sidebar-bottom { margin-top: auto; padding-top: 28px; }
.app-sidebar-user { display: flex; align-items: center; gap: 10px; padding: 16px 14px; margin-bottom: 8px; border-top: 1px solid var(--border); color: var(--text-secondary); }
.app-user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.app-shell-main { box-sizing: border-box; min-width: 0; max-width: 100%; padding: 32px clamp(24px, 3.2vw, 48px); overflow-x: auto; }
.app-shell--authenticated > .app-shell-main { margin-left: var(--app-sidebar-width); max-width: calc(100% - var(--app-sidebar-width)); min-height: 100vh; }
.app-shell-main > * { min-width: 0; }
.app-shell-main:focus { outline: none; }
.app-shell-skip { position: fixed; z-index: 500; top: 12px; left: 12px; transform: translateY(-160%); padding: 10px 16px; border-radius: var(--radius-sm); background: var(--surface); color: var(--accent); }
.app-shell-skip:focus { transform: translateY(0); }
.app-nav-link:focus-visible, .app-icon-button:focus-visible, .app-brand:focus-visible, .app-shell-button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.app-icon-button { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 44px; height: 44px; padding: 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); cursor: pointer; }
.app-icon-button:hover { background: var(--surface-muted); color: var(--accent); }
.app-shell-button { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; padding: 10px 20px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--accent); color: var(--surface); font: inherit; text-decoration: none; cursor: pointer; }
.app-shell-button:hover { filter: brightness(.96); }
.app-shell-button--quiet { background: var(--surface); border-color: var(--border); color: var(--text-primary); }
.app-guest-header { display: flex; align-items: center; justify-content: space-between; padding: 24px clamp(20px, 4vw, 56px); border-bottom: 1px solid var(--border); background: var(--surface); }
.app-shell--guest > .app-shell-main { max-width: 1280px; margin: 0 auto; }
.app-mobile-header { display: none; }
.app-mobile-brand-group { display: flex; align-items: center; gap: 10px; }
[data-app-drawer-open][hidden] { display: none; }
.app-flashes { display: grid; gap: 10px; margin-bottom: 20px; }
.app-flash { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px 8px 18px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); background: var(--surface); font-size: 14px; overflow-wrap: anywhere; }
.app-flash--success { border-left-color: var(--success); }
.app-flash--warning { border-left-color: var(--warning); }
.app-flash--error, .app-flash--danger { border-left-color: var(--danger); }
/* Narrow compatibility adapters: no global .container/.btn/.card resets. */
.app-shell--guest[data-app-module="auth"] .login-wrapper { max-width: 400px; margin: 8vh auto; }
.app-shell--guest[data-app-module="auth"] .login-card { padding: 28px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.app-shell--guest[data-app-module="auth"] .login-card h2 { margin-top: 0; font-size: 22px; }
.app-shell--guest[data-app-module="auth"] .login-card form > div { margin-bottom: 18px; }
.app-shell--guest[data-app-module="auth"] .login-card label { display: block; margin-bottom: 6px; }
.app-shell--guest[data-app-module="auth"] .login-card input:not([type="hidden"]):not([type="checkbox"]) { box-sizing: border-box; width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; }
.app-shell--guest[data-app-module="auth"] .login-card button[type="submit"] { width: 100%; min-height: 44px; border: 0; border-radius: var(--radius-sm); background: var(--accent); color: var(--surface); font: inherit; cursor: pointer; }
@media (max-width: 900px) {
  .app-sidebar { display: none; }
  .app-mobile-header { display: flex; align-items: center; justify-content: space-between; min-height: 64px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .app-brand--compact > strong { font-size: 23px; }
  .app-shell-main { padding: 20px; }
  .app-shell--authenticated > .app-shell-main { margin-left: 0; max-width: 100%; min-height: calc(100dvh - 64px); padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

}
@media (max-width: 380px) { .app-shell-main { padding-left: 14px; padding-right: 14px; } }
@media (prefers-reduced-motion: reduce) { .app-nav-link { transition: none; } }

/* Existing module layouts inside the narrower shell (layout only). */
.app-shell[data-app-module="news"] .news-container { grid-template-columns: 300px minmax(0, 1fr); }
.app-shell[data-app-module="news"] .news-main { min-width: 0; }
.app-shell[data-app-module="ds_chat"] #user-input { box-sizing: border-box; max-width: 100%; }
.app-shell[data-app-module="ds_chat"] .chat-history { min-height: 0; }
.app-shell[data-app-module="ds_chat"] .nav-center { min-width: 0; }
.app-shell[data-app-module="ds_chat"] .message-content { overflow-wrap: anywhere; }
.app-shell[data-app-module="accounting"] .record-form-container input,
.app-shell[data-app-module="accounting"] .record-form-container select,
.app-shell[data-app-module="accounting"] .record-form-container textarea { box-sizing: border-box; max-width: 100%; }
@media (max-width: 1100px) {
  .app-shell[data-app-module="news"] .news-container { grid-template-columns: minmax(0, 1fr); }
  .app-shell[data-app-module="ds_chat"] .chat-navbar { flex-wrap: wrap; gap: 15px; }
  .app-shell[data-app-module="ds_chat"] .nav-left,
  .app-shell[data-app-module="ds_chat"] .nav-center,
  .app-shell[data-app-module="ds_chat"] .nav-right { flex: 1 1 100%; justify-content: center; text-align: center; }
  .app-shell[data-app-module="ds_chat"] .session-info { align-items: center; }
  .app-shell[data-app-module="ds_chat"] .nav-center h3 { max-width: 100%; }
  .app-shell[data-app-module="ds_chat"] .chat-container { height: auto; min-height: calc(100dvh - 260px); }
}
@media (max-width: 768px) {
  .app-shell[data-app-module="user"] .login-table { width: 100%; margin-left: 0; padding: 0; }
}

/* Desktop sidebar: a remembered compact icon rail. Mobile navigation is independent. */
@media (min-width: 901px) {
  html[data-app-sidebar-collapsed="true"] .app-shell--authenticated { --app-sidebar-width: 72px; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar { padding-left: 12px; padding-right: 12px; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar-header { margin-left: 0; justify-content: center; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar-header > .app-brand { display: none; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar .app-nav-link { justify-content: center; padding: 12px; gap: 0; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar .app-nav-link > span,
  html[data-app-sidebar-collapsed="true"] .app-sidebar .app-user-name { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  html[data-app-sidebar-collapsed="true"] .app-sidebar-user { justify-content: center; padding: 16px 0; gap: 0; }
}
@media (min-width: 901px) and (prefers-reduced-motion: no-preference) {
  .app-sidebar-ready .app-sidebar { transition: width .18s ease, padding .18s ease; }
  .app-sidebar-ready .app-shell--authenticated > .app-shell-main { transition: margin-left .18s ease, max-width .18s ease; }
}

/* Narrow layouts use a native modal drawer; opening it never changes content width. */
.app-drawer { box-sizing: border-box; position: fixed; inset: 0 auto 0 0; margin: 0; width: min(300px, calc(100vw - 48px)); max-width: none; height: 100dvh; max-height: none; padding: max(22px, env(safe-area-inset-top, 0px)) 16px max(20px, env(safe-area-inset-bottom, 0px)); border: 0; border-right: 1px solid var(--border); background: var(--surface); color: var(--text-primary); overflow-y: auto; overscroll-behavior: contain; }
.app-drawer[open] { display: flex; flex-direction: column; }
.app-drawer::backdrop { background: rgb(35 43 61 / 28%); }
.app-drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 26px 10px; }
.app-drawer-main { display: grid; gap: 5px; }
html.app-drawer-open, html.app-drawer-open body.app-shell { overflow: hidden; }
@media (max-width: 900px) { .app-mobile-header { padding-left: 12px; } }

