:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --sidebar: #1f2937;
    --sidebar-strong: #111827;
    --sidebar-soft: #374151;
    --text: #172033;
    --muted: #64748b;
    --line: #d8e0ea;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --focus: #f59e0b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--sidebar);
    color: #f8fafc;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 14px 18px;
    background: var(--sidebar-strong);
    text-decoration: none;
}

.brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    object-fit: cover;
    background: #ffffff;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-nav {
    padding: 12px;
}

.menu,
.submenu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menu-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #e5e7eb;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.menu-toggle:hover,
.menu-section.is-open > .menu-toggle {
    background: var(--sidebar-soft);
    color: #ffffff;
}

.menu-toggle:focus-visible,
.submenu-link:focus-visible,
.brand:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.menu-chevron {
    flex: 0 0 auto;
    color: #cbd5e1;
    font-size: 12px;
    transition: transform 0.18s ease;
}

.menu-section.is-open .menu-chevron {
    transform: rotate(180deg);
}

.submenu {
    display: none;
    padding: 4px 0 10px;
}

.menu-section.is-open .submenu {
    display: block;
}

.submenu-link {
    display: block;
    margin: 2px 0;
    padding: 8px 12px 8px 24px;
    border-radius: 6px;
    color: #d1d5db;
    text-decoration: none;
}

.submenu-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.submenu-link.is-active {
    background: var(--primary-soft);
    color: #1d4ed8;
    font-weight: 700;
}

.content {
    min-width: 0;
    padding: 28px;
}

.content h1 {
    margin: 0 0 10px;
    font-size: 28px;
    line-height: 1.2;
}

.content h2 {
    margin: 24px 0 10px;
    font-size: 20px;
}

.content p {
    margin: 0 0 12px;
    color: var(--muted);
}

.content hr {
    margin: 24px 0;
    border: 0;
    border-top: 1px solid var(--line);
}

.content ul {
    padding-left: 22px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

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

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

.button-primary:hover {
    background: #1d4ed8;
}

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

.button-secondary:hover {
    background: #f8fafc;
}

.button-danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

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

.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 1080px;
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
}

.filter-field {
    display: grid;
    flex: 1 1 auto;
    gap: 6px;
    color: #334155;
    font-weight: 700;
}

.filter-field input {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    font-weight: 400;
}

.filter-field input:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(37, 99, 235, 0.16);
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.alert {
    max-width: 1080px;
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.alert-error {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.table-card,
.form-card {
    max-width: 1080px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.table-card {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

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

.data-table th {
    background: #f8fafc;
    color: #334155;
    font-size: 13px;
    text-transform: uppercase;
}

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

.actions-column {
    width: 1%;
}

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

.table-actions form {
    margin: 0;
}

.empty-state {
    color: var(--muted);
    text-align: center;
}

.form-card {
    padding: 20px;
}

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

.field {
    display: grid;
    gap: 6px;
    color: #334155;
    font-weight: 700;
}

.field-full {
    grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    font-weight: 400;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(37, 99, 235, 0.16);
}

.field input[readonly] {
    background: #f8fafc;
    color: var(--muted);
}

.field textarea {
    resize: vertical;
}

.field textarea[readonly] {
    background: #f8fafc;
    color: var(--muted);
}

.checkbox-field {
    align-content: start;
}

.checkbox-field input[type="checkbox"] {
    width: 22px;
    min-height: 22px;
}

.radio-field {
    align-content: start;
    margin: 0;
    padding: 0;
    border: 0;
}

.radio-field legend {
    margin-bottom: 6px;
}

.radio-field label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
    font-weight: 400;
}

.radio-field input[type="radio"] {
    width: 18px;
    min-height: 18px;
}

.radio-field.is-disabled {
    color: var(--muted);
}

.radio-field input[type="radio"]:disabled {
    cursor: not-allowed;
}

.lookup-field {
    display: flex;
    gap: 8px;
}

.lookup-field input {
    flex: 1 1 auto;
}

.lookup-button {
    flex: 0 0 auto;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.52);
}

.modal-backdrop[hidden] {
    display: none;
}

.lookup-modal {
    width: min(720px, 100%);
    max-height: min(680px, 92vh);
    overflow: hidden;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.3);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.modal-header h2 {
    margin: 0 0 4px;
}

.lookup-search {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.lookup-results {
    max-height: 360px;
    overflow-y: auto;
    padding: 8px;
}

.lookup-row {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.lookup-row-three {
    grid-template-columns: 120px minmax(0, 1fr) 90px;
}

.lookup-row:hover,
.lookup-row:focus-visible {
    background: var(--primary-soft);
    outline: none;
}

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    width: min(460px, 100%);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
}

.auth-logo {
    width: 92px;
    height: 56px;
    object-fit: contain;
    margin-bottom: 12px;
}

.auth-card .field {
    margin-top: 14px;
}

.auth-actions {
    justify-content: space-between;
}

.alert-success {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.home-header {
    display: flex;
    align-items: center;
    gap: 18px;
}

.home-logo {
    flex: 0 0 auto;
    width: 78px;
    height: 78px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    object-fit: contain;
    padding: 6px;
}

.placeholder-card,
.content-card {
    max-width: 860px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
}

.placeholder-card {
    margin-top: 20px;
}

code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #eef2f7;
    color: #334155;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
        max-height: 55vh;
    }

    .content {
        padding: 20px;
    }

    .home-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-header,
    .filter-bar,
    .filter-actions,
    .table-actions,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .lookup-field,
    .lookup-search,
    .modal-header {
        align-items: stretch;
        flex-direction: column;
    }

    .lookup-row {
        grid-template-columns: 1fr;
    }

    .lookup-row-three {
        grid-template-columns: 1fr;
    }
}
