/* Shared finishing layer: calm surfaces, readable controls and clear hierarchy. */
:root {
  --navy: #183353;
  --blue: #3569b4;
  --ink: #24364b;
  --muted: #627185;
  --pale: #f0f5fa;
  --paper: #f5f7fa;
  --line: #e2e8f0;
  --shadow: 0 3px 14px rgba(24, 51, 83, .035);
}
body { background: var(--paper); font-family: "DM Sans", system-ui, sans-serif; }
/* Let intrinsic content wrap; never conceal page-width layout errors. */
html, body { overflow-x: visible; }
.form-grid { align-items: start; }
.field, .search-form label, .recommend-form label, .year-grid label { min-width: 0; align-content: start; align-items: start; }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select { height: 48px; align-self: start; }
.field small, .password-strength { text-transform: none; letter-spacing: normal; overflow-wrap: anywhere; }
.form-grid > *, .workspace-grid > *, .book-summary > *, .dashboard-header > *, .library-header > *, .admin-head > * { min-width: 0; }
.form-actions, .head-links, .header-actions, .actions, .pagination { flex-wrap: wrap; }
.button, .small-button, .compare-button, label, .alert { white-space: normal; overflow-wrap: anywhere; }
.table-wrap { min-width: 0; width: 100%; }
.metric, .metric-grid > * { min-width: 0; }
.metric strong, .metric span { overflow-wrap: anywhere; }
dialog { box-sizing: border-box; width: min(640px, calc(100% - 32px)); max-width: calc(100% - 32px); max-height: calc(100dvh - 32px); overflow: auto; }
.sidebar > * { flex-shrink: 0; }
.sidebar-footer > div { min-width: 0; overflow-wrap: anywhere; }
button, input, select, textarea { font: inherit; }
:where(a, button, summary, input, select, textarea):focus-visible {
  outline: 3px solid #759edf;
  outline-offset: 3px;
}
.dashboard-header h1, .library-header h1, .admin-head h1 {
  font-size: clamp(1.65rem, 2.6vw, 2.35rem);
  line-height: 1.2;
  letter-spacing: -.035em;
}
.dashboard-header { margin-bottom: 28px; }
.dashboard-header p:last-child, .admin-head p, .panel-help { line-height: 1.65; }
.eyebrow { letter-spacing: .1em; font-size: .68rem; margin-bottom: 8px; }
.dashboard-main { width: 100%; max-width: 1500px; margin-inline: auto; padding: 36px clamp(20px, 3vw, 48px); }
.library-main { width: 100%; max-width: 1500px; margin-inline: auto; padding: 36px clamp(20px, 3vw, 48px); }
.admin-main { padding-top: 0; }
.admin-wrap { max-width: 1280px; margin-inline: auto; }
.sidebar { background: #183353; }
.sidebar .side-nav { margin-top: 34px; gap: 5px; }
.sidebar .side-nav a, .side-nav-group summary { border-radius: 8px; font-weight: 500; line-height: 1.5; }
.sidebar .side-nav a { color: #c7d5e7; }
.sidebar .side-nav a.active { background: #2b496b; color: white; box-shadow: inset 3px 0 #7db4f3; }
.sidebar .side-nav a:hover { background: #254362; color: white; }
.sidebar .side-nav span { color: #a9c9ed; }
.sidebar .side-nav-group summary { color: #b6c8dc; font-size: .77rem; }
.sidebar-footer { margin-top: auto; padding-top: 20px; }
.panel, .section, .library-panel, .metric-card, .metric, .quick-actions {
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.panel, .section, .library-panel { padding: clamp(18px, 2vw, 28px); }
.panel-heading { gap: 16px; padding-bottom: 18px; align-items: center; }
.panel h2, .section > h2, .library-panel h2 { font-size: 1.2rem; letter-spacing: -.025em; line-height: 1.35; }
.panel-mark { display: none; }
.metric-grid { gap: 16px; }
.metric-card { min-height: 118px; padding: 22px; border-top-width: 1px; }
.metric-card strong { font-size: 2rem; margin: 12px 0 0; }
.metric-card span, .metric span { font-size: .8rem; }
.metric { border-top-width: 1px; }
.quick-actions { background: #edf3fa; border-left: 1px solid var(--line); gap: 24px; padding: 24px; }
.quick-actions h2 { font-size: 1.35rem; line-height: 1.3; }
.quick-links a { border-radius: 10px; padding: 16px; }
.quick-links a:hover { transform: none; border-color: #b6cae4; }
.quick-links strong { font-size: .82rem; }
.quick-links small { font-size: .72rem; line-height: 1.5; }
.quick-icon, .activity-icon { border-radius: 8px; }
.activity-item { padding-block: 16px; }
.activity-item strong { font-size: .86rem; }
.activity-item p { font-size: .79rem; line-height: 1.6; }
.activity-item time { color: var(--muted); font-size: .7rem; }
.chart-section, .summary-grid { margin-top: 24px; }
.chart-card { border-radius: 10px; box-shadow: none; }
.button, .small-button, .compare-button {
  border-radius: 8px;
  min-height: 40px;
  justify-content: center;
  line-height: 1.4;
  cursor: pointer;
}
.button { min-height: 44px; font-size: .85rem; font-weight: 600; }
.button-primary { background: var(--navy); color: #fff; }
.button-primary:hover { background: #254b76; }
.field, .search-form label, .recommend-form label { font-size: .82rem; line-height: 1.6; }
.search-form label, .recommend-form label, .year-grid label { text-transform: none; letter-spacing: 0; font-weight: 500; }
.search-form { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  border-radius: 8px;
  border: 1px solid #cdd7e3;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
}
input::placeholder, textarea::placeholder { color: #788697; }
.form-grid { gap: 18px; }
.form-actions { gap: 10px; margin-top: 20px; }
.table-wrap { box-shadow: none; border-radius: 10px; }
.table-wrap th { text-transform: none; letter-spacing: 0; font-size: .78rem; font-weight: 600; }
.table-wrap td { font-size: .82rem; padding: 14px 12px; }
.badge, .filter-chip { border-radius: 6px; letter-spacing: 0; font-weight: 600; }
.alert { border-radius: 10px; line-height: 1.6; }
.book-card { border-radius: 10px; box-shadow: none; padding: 20px; margin-bottom: 12px; }
.book-card h3 { font-size: 1.05rem; line-height: 1.4; }
.book-card small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.65; }
.book-card p, .book-meta span { font-size: .8rem; }
.book-kicker { text-transform: none; letter-spacing: 0; }
.recommend-panel { background: #fff; }
.recommend-form { gap: 16px; }
.recommend-form small, .panel-help { color: var(--muted); font-size: .78rem; }
.advanced-filters { grid-column: 1 / -1; border-block: 1px solid var(--line); padding-block: 12px; }
.advanced-filters summary { cursor: pointer; font-size: .83rem; font-weight: 600; color: var(--navy); padding: 4px 0; }
.advanced-filters summary span { font-weight: 400; color: var(--muted); margin-left: 10px; font-size: .76rem; }
.advanced-filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.filter-actions { grid-column: 1 / -1; }
.auth-card { max-width: 500px; margin-inline: auto; }
.auth-card h2 { letter-spacing: -.03em; }
.auth-main { padding: clamp(24px, 5vw, 72px); }
.auth-card .field { margin-bottom: 18px; }
.brand-panel { background: var(--navy); }
.container { max-width: 1360px; margin-inline: auto; }
.feature-card, .role-card { border-radius: 14px; box-shadow: var(--shadow); }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 100; padding: 12px 18px; background: white; color: var(--navy); border-radius: 8px; }
.skip-link:focus { top: 12px; }
@media (min-width: 821px) {
  .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
@media (max-width: 820px) {
  .dashboard-main { padding: 76px 20px 32px; }
  .library-main { padding: 76px 20px 32px; }
  .admin-main { padding-top: 48px; }
  .sidebar .side-nav { margin-top: 32px; }
  .quick-actions { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .dashboard-main { padding-inline: 14px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-card { min-height: 110px; padding: 16px; }
  .metric-card strong { font-size: 1.7rem; }
  .metric-card span { font-size: .73rem; }
  .advanced-filter-grid { grid-template-columns: 1fr; }
  .search-form { grid-template-columns: 1fr; }
  .advanced-filters summary span { display: block; margin-left: 18px; }
  .quick-links { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; flex-wrap: wrap; }
  .auth-main { padding: 28px 20px; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea { font-size: 16px; }
}
@media print {
  .skip-link, .advanced-filters { display: none; }
  .dashboard-main { max-width: none; padding: 0; }
  .panel, .section, .library-panel, .metric-card { box-shadow: none; }
}

/* Final layout rules follow component polish so breakpoints stay authoritative. */
/* Keep the original two/three-column limit, collapsing by available space. */
.form-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, max(240px, calc(50% - 9px))), 1fr)); }
.form-grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, max(240px, calc(33.333% - 12px))), 1fr)); }
.book-summary { min-width: 0; }
.sidebar .side-nav a, .sidebar .side-nav summary { overflow-wrap: anywhere; }
.sidebar .side-nav span, .sidebar-footer .status-dot { flex-shrink: 0; }
.table-wrap:not(.stacked-wrap):not(.accounts-wrap) > table { min-width: 600px; }
@media screen and (min-width: 821px) {
  html:has(.dashboard-shell, .library-shell), body:has(.dashboard-shell, .library-shell) { overflow: visible; }
}
@media screen and (max-width: 1100px) {
  .history-item { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (max-width: 820px) {
  .dashboard-shell, .library-shell, .admin-shell { display: block; height: auto; max-height: none; overflow: visible; }
  .dashboard-main, .library-main, .dashboard-main.admin-main, .admin-main { margin: 0; width: 100%; height: auto; max-height: none; padding: 76px clamp(12px, 3vw, 20px) 32px; overflow: visible; }
  .dashboard-shell .sidebar, .library-shell .sidebar, .admin-shell .sidebar { visibility: hidden; }
  body.sidebar-open .sidebar { visibility: visible; }
  .admin-wrap, .form-wrap { padding-inline: 0; }
  .admin-page .admin-wrap, .admin-page .form-wrap { margin-left: 0; width: 100%; }
}
@media screen and (max-width: 540px) {
  .form-grid, .form-grid.three, .advanced-filter-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid > .full { grid-column: 1 / -1; }
  .book-summary { flex-wrap: wrap; }
  .card-actions > *, .filter-actions > *, .head-links > * { min-width: 0; max-width: 100%; }
  .card-actions form button { width: 100%; }
  .account-status { white-space: normal; }
}

