:root {
    color-scheme: light;
    --color-ink: #111827;
    --color-muted: #64748b;
    --color-subtle: #94a3b8;
    --color-border: #e2e8f0;
    --color-panel: #ffffff;
    --color-page: #eef3f8;
    --color-sidebar: #101a2b;
    --color-sidebar-soft: #1c2a41;
    --color-primary: #2869e8;
    --color-primary-strong: #1d4fd7;
    --color-primary-soft: #eaf1ff;
    --color-accent: #dc4c4c;
    --color-success: #1f9d68;
    --color-warning: #f08a24;
    --color-purple: #7c6ee6;
    --shadow-panel: 0 10px 28px rgba(15, 23, 42, 0.09);
    --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.06);
    --sidebar-width: 248px;
    --topbar-height: 64px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--color-ink);
    background: var(--color-page);
    font-family: Arial, "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

a {
    color: inherit;
}

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

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

.app-header {
    min-height: 0;
}

.auth-page .app-header {
    min-height: 64px;
    display: flex;
    align-items: center;
    padding: 0 32px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.9);
}

.app-header:has(.auth-brand) {
    min-height: 64px;
    display: flex;
    align-items: center;
    padding: 0 32px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.94);
}

.app-header:has(.auth-brand) + .page-shell {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0 56px;
}

.auth-brand {
    color: var(--color-primary-strong);
    font-size: 17px;
    font-weight: 800;
    text-decoration: none;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 22px 14px 16px;
    color: #cbd5e1;
    background:
        radial-gradient(circle at 25% 8%, rgba(59, 130, 246, 0.16), transparent 34%),
        linear-gradient(180deg, #101a2b 0%, #172235 46%, #0f1726 100%);
    box-shadow: 12px 0 30px rgba(15, 23, 42, 0.18);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 12px;
    color: #ffffff;
    font-size: 17px;
    font-weight: 800;
    text-decoration: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    color: #102033;
    background: #ffffff;
    font-size: 15px;
}

.role-workbench {
    margin-top: 24px;
    padding: 0 0 14px;
}

.sidebar-section-title {
    margin: 0 0 10px;
    padding: 0 12px;
    color: #91a2bd;
    font-size: 13px;
    font-weight: 700;
}

.role-chip {
    min-height: 38px;
    display: grid;
    grid-template-columns: 28px 1fr;
    grid-template-rows: auto auto;
    gap: 0 9px;
    align-items: center;
    margin: 8px 0;
    padding: 8px 11px;
    border-radius: 7px;
    color: #ffffff;
    text-decoration: none;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16);
}

.role-chip span {
    grid-row: 1 / 3;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
    font-size: 13px;
    font-weight: 800;
}

.role-chip strong {
    line-height: 1.1;
}

.role-chip small {
    color: rgba(255, 255, 255, 0.82);
    font-size: 11px;
}

.role-chip-admin {
    background: linear-gradient(135deg, #316cf4, #1f57d8);
}

.role-chip-librarian {
    background: linear-gradient(135deg, #4db7ad, #278f87);
}

.role-chip-reader {
    background: linear-gradient(135deg, #ffac48, #f08a24);
}

.side-nav {
    display: grid;
    gap: 5px;
    margin-top: 4px;
}

.side-nav-link {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    border-radius: 7px;
    color: #c8d2df;
    text-decoration: none;
}

.side-nav-link span {
    width: 22px;
    display: inline-flex;
    justify-content: center;
    color: #9aa9bd;
    font-size: 13px;
    font-weight: 800;
}

.side-nav-link:hover,
.side-nav-link.is-active {
    color: #ffffff;
    background: linear-gradient(135deg, #2f6df3, #1f58d8);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.side-nav-link:hover span,
.side-nav-link.is-active span {
    color: #ffffff;
}

.sidebar-footer {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: auto;
    padding: 10px 12px 0;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    color: #9aa9bd;
}

.sidebar-footer a {
    color: #cbd5e1;
    font-size: 13px;
    text-decoration: none;
}

.sidebar-menu-dot {
    color: #91a2bd;
    font-size: 20px;
}

.app-topbar {
    position: fixed;
    inset: 0 0 auto var(--sidebar-width);
    z-index: 25;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 28px;
    border-bottom: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.05);
}

.breadcrumb {
    flex: 1;
    min-width: 160px;
    color: #475569;
    font-size: 13px;
    font-weight: 700;
}

.breadcrumb span {
    margin: 0 10px;
    color: #cbd5e1;
}

.global-search {
    width: min(360px, 34vw);
    min-width: 240px;
    height: 38px;
    display: flex;
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: 7px;
    background: #ffffff;
}

.global-search input {
    width: 100%;
    height: 100%;
    padding: 0 12px;
    border: 0;
    outline: 0;
    color: var(--color-ink);
    background: transparent;
}

.global-search button {
    width: 40px;
    height: 100%;
    border: 0;
    color: #64748b;
    background: transparent;
    cursor: pointer;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 11px;
    color: #334155;
    white-space: nowrap;
}

.notification-dot {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    color: #ffffff;
    background: #ef4444;
    font-size: 12px;
    font-weight: 800;
}

.avatar {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #102033;
    background: linear-gradient(135deg, #dbeafe, #ffffff);
    font-weight: 800;
    box-shadow: inset 0 0 0 1px #bfdbfe;
}

.user-pill,
.role-label {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-pill {
    font-weight: 700;
}

.role-label {
    color: #64748b;
    font-size: 13px;
}

.auth-page {
    background:
        linear-gradient(rgba(245, 247, 251, 0.86), rgba(245, 247, 251, 0.94)),
        url("../images/library-login.svg") center / cover no-repeat;
}

.auth-shell {
    width: min(1120px, calc(100% - 32px));
    min-height: calc(100vh - 64px);
    display: grid;
    align-items: center;
    margin: 0 auto;
    padding: 48px 0;
}

.page-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 56px;
}

body:not(.auth-page) .page-shell {
    width: auto;
    max-width: none;
    margin-left: var(--sidebar-width);
    padding: calc(var(--topbar-height) + 18px) 24px 44px;
}

.login-panel,
.notice-panel,
.dashboard-hero,
.workspace-card,
.toolbar-panel,
.table-panel,
.form-panel,
.report-card,
.dashboard-panel,
.metric-card,
.shortcut-card {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-panel);
    box-shadow: var(--shadow-panel);
}

.login-panel {
    width: min(420px, 100%);
    padding: 32px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--color-primary);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 10px;
    font-size: 27px;
    line-height: 1.18;
}

h2 {
    margin-bottom: 10px;
    font-size: 18px;
    line-height: 1.25;
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-form label,
.search-form label,
.dashboard-search-form label,
.form-field label {
    color: #475569;
    font-size: 13px;
    font-weight: 800;
}

.login-form input,
.search-form input,
.search-form select,
.dashboard-search-form input,
.dashboard-search-form select,
.book-form input,
.book-form select,
.category-form input,
.category-form textarea,
.reader-form input,
.reader-form select,
.user-form input,
.user-form select,
.borrow-form input {
    width: 100%;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-ink);
    background: #ffffff;
    outline: 0;
}

.login-form input:focus,
.search-form input:focus,
.search-form select:focus,
.dashboard-search-form input:focus,
.dashboard-search-form select:focus,
.book-form input:focus,
.book-form select:focus,
.category-form input:focus,
.category-form textarea:focus,
.reader-form input:focus,
.reader-form select:focus,
.user-form input:focus,
.user-form select:focus,
.borrow-form input:focus,
.global-search:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(40, 105, 232, 0.14);
}

.button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button-primary {
    color: #ffffff;
    background: var(--color-primary);
    box-shadow: 0 6px 14px rgba(40, 105, 232, 0.22);
}

.button-primary:hover {
    background: var(--color-primary-strong);
}

.button-secondary {
    color: #475569;
    border-color: var(--color-border);
    background: #ffffff;
}

.button-secondary:hover {
    color: var(--color-primary-strong);
    border-color: #bcd0ff;
    background: #f8fbff;
}

.button-danger {
    color: #ffffff;
    background: var(--color-accent);
}

.button-danger:hover {
    background: #b93737;
}

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

.login-form .button-primary {
    margin-top: 12px;
}

.message {
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.message-error {
    color: #9f1d1d;
    border: 1px solid rgba(220, 76, 76, 0.26);
    background: #fff1f1;
}

.message-success {
    color: #11633f;
    border: 1px solid rgba(31, 157, 104, 0.26);
    background: #ecfdf5;
}

.dashboard-hero {
    padding: 24px;
    margin-bottom: 16px;
}

.dashboard-welcome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.dashboard-welcome p:last-child,
.workspace-card p:last-child,
.notice-panel p:last-child {
    margin-bottom: 0;
}

.welcome-user {
    min-width: 150px;
    display: grid;
    gap: 4px;
    padding: 11px 14px;
    border: 1px solid #dbeafe;
    border-radius: 8px;
    background: var(--color-primary-soft);
}

.welcome-user span {
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
}

.welcome-user strong {
    color: var(--color-primary-strong);
}

.dashboard-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.metric-card {
    min-height: 98px;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 18px 20px;
}

.metric-card h2 {
    margin-bottom: 5px;
    color: #475569;
    font-size: 13px;
}

.metric-icon {
    width: 52px;
    height: 52px;
    display: inline-flex;
    flex: 0 0 52px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
}

.metric-blue {
    background: linear-gradient(135deg, #4b83f3, #2869e8);
}

.metric-green {
    background: linear-gradient(135deg, #5ccaae, #1f9d68);
}

.metric-orange {
    background: linear-gradient(135deg, #ffb25c, #f08a24);
}

.metric-purple {
    background: linear-gradient(135deg, #9187f1, #6f60e5);
}

.metric-value {
    margin-bottom: 4px;
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
}

.metric-value small {
    font-size: 13px;
    font-weight: 800;
}

.metric-trend {
    margin-bottom: 0;
    color: #64748b;
    font-size: 12px;
}

.trend-up {
    color: #e05252;
}

.trend-down {
    color: #1f9d68;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(320px, 0.96fr) minmax(420px, 1.34fr);
    gap: 16px;
    margin-bottom: 16px;
}

.dashboard-panel {
    padding: 16px;
}

.dashboard-panel h2 {
    margin-bottom: 14px;
    font-size: 16px;
}

.dashboard-search-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px 22px;
    align-items: end;
}

.search-field {
    display: grid;
    gap: 7px;
}

.dashboard-form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-heading h2 {
    margin-bottom: 0;
}

.panel-heading span,
.table-panel-compact h2 span {
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
}

.panel-heading a,
.text-link {
    color: var(--color-primary);
    font-weight: 800;
    text-decoration: none;
}

.rank-chart {
    height: 162px;
    display: grid;
    grid-template-columns: repeat(10, minmax(36px, 1fr));
    align-items: end;
    gap: 12px;
    padding: 6px 4px 0;
    border-top: 1px solid #eef2f7;
    background:
        linear-gradient(to top, rgba(226, 232, 240, 0.62) 1px, transparent 1px) 0 0 / 100% 32px;
}

.rank-item {
    height: 138px;
    display: grid;
    grid-template-rows: 18px 1fr 22px;
    justify-items: center;
    align-items: end;
    min-width: 0;
}

.rank-value {
    color: #475569;
    font-size: 11px;
    font-weight: 800;
}

.rank-bar {
    width: 24px;
    height: var(--bar-height);
    min-height: 18px;
    border-radius: 4px 4px 0 0;
    background: linear-gradient(180deg, #4b83f3, #2869e8);
    box-shadow: 0 4px 10px rgba(40, 105, 232, 0.18);
}

.rank-item small {
    max-width: 68px;
    overflow: hidden;
    color: #475569;
    font-size: 11px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-table-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(300px, 0.9fr);
    gap: 16px;
}

.table-panel-wide {
    grid-column: span 1;
}

.table-panel-compact {
    min-width: 0;
    padding: 14px 16px;
}

.table-panel-compact h2 {
    margin-bottom: 12px;
    font-size: 16px;
}

.shortcut-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.reader-shortcut-grid {
    margin-top: 16px;
}

.shortcut-card {
    min-height: 100px;
    display: grid;
    grid-template-columns: 46px 1fr 14px;
    grid-template-rows: auto auto;
    gap: 5px 13px;
    align-items: center;
    padding: 16px;
    text-decoration: none;
}

.shortcut-card::after {
    content: "›";
    grid-row: 1 / 3;
    grid-column: 3;
    color: #94a3b8;
    font-size: 24px;
}

.shortcut-card strong {
    align-self: end;
}

.shortcut-card small {
    align-self: start;
    color: #64748b;
    line-height: 1.35;
}

.shortcut-icon {
    grid-row: 1 / 3;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-weight: 900;
}

.shortcut-blue {
    color: #2454cb;
    background: #eaf1ff;
}

.shortcut-green {
    color: #16825a;
    background: #dcfce7;
}

.shortcut-orange {
    color: #c46615;
    background: #fff3df;
}

.shortcut-purple {
    color: #6254d6;
    background: #eeeaff;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 16px;
}

.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.workspace-card {
    min-height: 156px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 20px;
}

.workspace-card p {
    color: var(--color-muted);
}

.workspace-card .button {
    margin-top: auto;
}

.report-card {
    min-height: 136px;
    padding: 18px;
}

.report-card h2 {
    color: var(--color-muted);
    font-size: 13px;
}

.report-card-alert {
    border-color: rgba(220, 76, 76, 0.28);
}

.report-metric {
    margin-bottom: 0;
    color: var(--color-primary-strong);
    font-size: 32px;
    font-weight: 900;
    line-height: 1;
}

.notice-panel {
    max-width: 680px;
    padding: 28px;
}

.role-actions {
    margin-top: 18px;
}

.catalog-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

.catalog-hero .button {
    margin-top: 0;
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-panel,
.table-panel,
.form-panel {
    padding: 20px;
    margin-bottom: 18px;
}

.search-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto auto;
    gap: 10px;
    align-items: end;
}

.borrowing-search-form {
    grid-template-columns: repeat(3, minmax(130px, 1fr)) auto auto;
}

.system-log-search-form {
    grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

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

.dashboard-data-table {
    min-width: 720px;
    font-size: 12px;
}

.borrowing-table {
    min-width: 980px;
}

.user-table,
.system-log-table,
.category-table {
    min-width: 980px;
}

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

.dashboard-data-table th,
.dashboard-data-table td {
    padding: 7px 8px;
}

.data-table th {
    color: #475569;
    font-size: 12px;
    font-weight: 900;
    background: #f8fafc;
}

.data-table tbody tr:hover {
    background: #f8fbff;
}

.empty-state {
    margin-bottom: 0;
    color: var(--color-muted);
}

.status-pill {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-available,
.status-active,
.status-success {
    color: #148158;
    background: #dcfce7;
}

.status-unavailable,
.status-suspended {
    color: #b45309;
    background: #fff3df;
}

.status-archived,
.status-inactive,
.status-returned,
.status-unknown {
    color: #64748b;
    background: #eef2f7;
}

.status-failure,
.status-overdue {
    color: #c24141;
    background: #fee2e2;
}

.stock-plus {
    color: #16a34a;
    font-weight: 800;
}

.stock-return {
    color: #1d4ed8;
    font-weight: 800;
}

.overdue-days {
    color: #dc2626;
    font-weight: 900;
}

.muted-text {
    color: var(--color-muted);
    font-size: 12px;
}

.table-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.table-actions form {
    margin: 0;
}

.form-panel {
    max-width: 900px;
}

.book-form,
.category-form,
.reader-form,
.user-form,
.borrow-form {
    display: grid;
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

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

.form-field-wide {
    grid-column: 1 / -1;
}

.category-form textarea {
    min-height: 112px;
    resize: vertical;
}

.field-error {
    color: #b93737;
    font-size: 13px;
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 1180px) {
    .dashboard-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .dashboard-table-grid {
        grid-template-columns: 1fr;
    }

    .shortcut-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 960px) {
    .app-sidebar,
    .app-topbar {
        position: static;
        width: auto;
        inset: auto;
    }

    .app-sidebar {
        min-height: auto;
        border-radius: 0;
    }

    .app-topbar {
        height: auto;
        flex-wrap: wrap;
        padding: 14px 16px;
    }

    body:not(.auth-page) .page-shell {
        width: min(1280px, calc(100% - 24px));
        margin: 0 auto;
        padding: 18px 0 40px;
    }

    .global-search {
        width: 100%;
    }
}

@media (max-width: 720px) {
    .auth-page .app-header {
        padding: 0 16px;
    }

    h1 {
        font-size: 24px;
    }

    .dashboard-welcome,
    .catalog-hero {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-metrics,
    .dashboard-search-form,
    .shortcut-grid,
    .search-form,
    .borrowing-search-form,
    .system-log-search-form,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .rank-chart {
        grid-template-columns: repeat(5, minmax(36px, 1fr));
        height: auto;
    }

    .rank-item {
        height: 132px;
    }

    .login-panel,
    .notice-panel,
    .dashboard-hero,
    .workspace-card,
    .report-card,
    .toolbar-panel,
    .table-panel,
    .form-panel,
    .dashboard-panel,
    .metric-card,
    .shortcut-card {
        box-shadow: none;
    }
}
