:root {
    --primary: #1f4e79;
    --primary-dark: #183f63;
    --primary-soft: #2f5f8c;
    --drawer-bg: #0f1724;
    --drawer-accent: #2f4461;
    --drawer-text: #dbe7f6;
    --border: #d7dde3;
    --bg: #f5f7fa;
}

* { box-sizing: border-box; }

body {
    font-family: Segoe UI, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: #202124;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--primary-dark);
    box-shadow: 0 2px 12px rgba(11, 22, 34, 0.28);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(100deg, var(--primary-dark), var(--primary));
    color: #fff;
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.4px;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 44px;
    height: 44px;
    display: inline-block;
    flex-shrink: 0;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 20px;
}

.topbar-nav a {
    color: #eaf3fc;
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.topbar-nav a:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.topbar-nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.24);
    color: #ffffff;
}

.nav-notification-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
}

.nav-bell-icon {
    font-size: 15px;
    line-height: 1;
}

.nav-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #e02424;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    position: absolute;
    top: -7px;
    right: -10px;
    border: 1px solid rgba(24, 63, 99, 0.95);
}

.topbar-project {
    margin-left: auto;
    color: #cfe0f0;
    font-size: 13px;
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 4px;
    padding: 3px 10px;
    white-space: nowrap;
}

.topbar-user {
    color: #cfe0f0;
    font-size: 13px;
}

.topbar-spacer {
    margin-left: auto;
}

.topbar-logout-form {
    margin: 0;
}

.topbar-logout-btn {
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 8px;
    min-height: 38px;
    padding: 0 14px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.topbar-logout-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.container {
    max-width: 1100px;
    margin: 22px auto;
    padding: 0 16px;
}

.modal-stage {
    position: relative;
    min-height: calc(100vh - 82px);
    padding: 26px 16px 30px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 12% 18%, rgba(47, 95, 140, 0.26), transparent 45%),
        radial-gradient(circle at 85% 78%, rgba(24, 63, 99, 0.22), transparent 50%),
        linear-gradient(180deg, #eef3f8 0%, #e6edf6 100%);
    z-index: 0;
}

.modal-shell {
    position: relative;
    z-index: 1;
    width: min(1120px, 100%);
    max-height: calc(100vh - 130px);
    overflow: auto;
    border: 1px solid #c8d3df;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 24px 60px rgba(15, 31, 49, 0.28);
    animation: modal-rise 0.25s ease-out;
}

.modal-page {
    padding: 20px;
}

@keyframes modal-rise {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.alert { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; }
.alert-success { background: #e6f4ea; color: #1e7e34; border: 1px solid #b7e1c1; }
.alert-danger { background: #fdecea; color: #a12622; border: 1px solid #f5c6c3; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 14px; }
th { background: #eef2f6; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 20px; margin-bottom: 16px; }

.auth-logo-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.auth-logo {
    width: 62px;
    height: 62px;
    display: block;
}

form label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13px; }

input[type=text],
input[type=email],
input[type=password],
textarea,
select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
}

textarea { min-height: 90px; }

button.btn,
.btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    line-height: 1;
    text-decoration: none;
}

.btn-secondary {
    background: #e8eef5;
    color: #183f63;
    border: 1px solid #c8d4e0;
}

.btn-danger {
    background: #c53f3a;
    color: #fff;
}

.btn-sm {
    font-size: 14px;
    min-height: 38px;
    padding: 0 14px;
    margin-top: 0;
}

.btn-inline {
    margin-top: 0;
    margin-left: 8px;
    min-height: 38px;
    padding: 0 14px;
    font-size: 14px;
}

button:not(.topbar-logout-btn):not(.link-button) {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    min-height: 38px;
    padding: 0 14px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button.btn:hover,
.btn:hover,
button:not(.topbar-logout-btn):not(.link-button):hover {
    background: var(--primary-soft);
    color: #fff;
}

.btn-secondary:hover {
    background: #dce7f2;
    color: #112f4a;
}

.btn-danger:hover {
    background: #a8312c;
    color: #fff;
}

button.btn:focus-visible,
.btn:focus-visible,
button:not(.topbar-logout-btn):not(.link-button):focus-visible,
.topbar-logout-btn:focus-visible,
.link-button:focus-visible {
    outline: 2px solid #7eb5ec;
    outline-offset: 2px;
}

button.btn:disabled,
.btn.disabled,
button:disabled:not(.link-button) {
    opacity: 0.65;
    cursor: not-allowed;
}

.register-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.register-search-group {
    min-width: 220px;
    max-width: 340px;
    flex: 1 1 280px;
}

.register-search-btn {
    margin-top: 0;
}

.register-toolbar .btn {
    margin-top: 0;
}

.register-summary {
    color: #54616f;
    font-size: 13px;
    margin-bottom: 10px;
}

.pager {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.pager-link {
    color: #fff;
    background: var(--primary);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
}

.pager-link.disabled {
    background: #9ba5b1;
    pointer-events: none;
}

.pager-info {
    font-size: 13px;
    color: #394653;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.link-button {
    border: none;
    background: none;
    color: #1f4e79;
    cursor: pointer;
    padding: 0;
    font: inherit;
    text-decoration: underline;
}

.link-button:hover {
    color: #183f63;
}

.details-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.details-table th,
.details-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}

.details-table th {
    width: 220px;
    background: #f2f6fa;
}

.status-pill { padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.status-Draft { background: #eee; color: #555; }
.status-PendingApproval { background: #fff4ce; color: #8a6d00; }
.status-Approved { background: #e6f4ea; color: #1e7e34; }
.status-Rejected { background: #fdecea; color: #a12622; }
.validation-summary-errors ul { color: #a12622; }

.signature-card {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    background: #f8fafc;
}

.signature-pad {
    width: 100%;
    max-width: 700px;
    border: 1px dashed #8da2b8;
    border-radius: 4px;
    background: #fff;
    touch-action: none;
}

.signature-actions {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.esi-sheet {
    border: 1px solid #b4b9bf;
    border-radius: 10px;
    overflow: hidden;
    background: #fffef7;
    box-shadow: 0 18px 38px rgba(41, 54, 66, 0.16);
}

.esi-sheet-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    background: linear-gradient(180deg, #fcfcfb, #f1f2ea);
    border-bottom: 1px solid #c8ccb8;
}

.esi-sheet-header h2 {
    margin: 0;
    font-size: 28px;
    letter-spacing: 0.04em;
}

.esi-sheet-header p {
    margin: 6px 0 0;
    color: #5a5d52;
}

.esi-sheet-badge {
    min-width: 180px;
    padding: 12px 14px;
    border: 1px solid #d0d4c1;
    border-radius: 10px;
    background: #fffbe2;
    text-align: right;
}

.esi-sheet-badge-label {
    display: block;
    color: #6b6a57;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.esi-sheet-badge-value {
    display: block;
    margin-top: 4px;
    font-size: 20px;
    font-weight: 700;
    color: #243142;
}

.esi-form {
    padding: 0;
}

.esi-validation {
    margin: 18px 20px 0;
}

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

.esi-main {
    border-right: 1px solid #d4d7c8;
}

.esi-sidebar {
    background: #f8f8f1;
}

.esi-section {
    padding: 18px 20px;
    border-bottom: 1px solid #d4d7c8;
}

.esi-section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #495364;
}

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

.esi-field-grid-compact {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

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

.esi-field label,
.esi-choice-label {
    margin-top: 0;
    color: #384456;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
}

.esi-input,
.esi-textarea,
.esi-select {
    margin-top: 6px;
    border: 1px solid #bfc5b6;
    border-radius: 0;
    background: #fff9c9;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.esi-textarea {
    min-height: 124px;
    resize: vertical;
}

.esi-textarea-short {
    min-height: 92px;
}

.esi-help {
    margin-top: 6px;
    color: #69717d;
    font-size: 12px;
}

.esi-toggle-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.esi-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #c6ccbc;
    background: #ffffff;
    font-weight: 600;
}

.esi-toggle input {
    width: auto;
    margin: 0;
}

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

.esi-discipline-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #c6ccbc;
    background: #ffffff;
    font-weight: 500;
}

.esi-discipline-pill input {
    width: auto;
    margin: 0;
}

.esi-meta-list {
    display: grid;
    gap: 10px;
}

.esi-meta-row {
    padding: 12px;
    border: 1px solid #d0d4c1;
    background: #fff;
}

.esi-meta-label {
    display: block;
    color: #677182;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.esi-meta-value {
    display: block;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 700;
    color: #223140;
}

.esi-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 22px;
    background: #f4f5ee;
}

.esi-actions-note {
    color: #616c77;
    font-size: 13px;
}

#signatureHint {
    color: #54616f;
    font-size: 13px;
}

@media (max-width: 960px) {
    .topbar {
        flex-wrap: wrap;
    }

    .topbar-nav {
        width: 100%;
        margin-left: 0;
        order: 3;
        margin-top: 6px;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .topbar-user {
        display: none;
    }

    .topbar-logout-btn {
        min-height: 34px;
        padding: 0 10px;
        font-size: 12px;
    }

    .modal-stage {
        min-height: calc(100vh - 118px);
        padding: 14px 10px 18px;
    }

    .modal-shell {
        max-height: calc(100vh - 150px);
        border-radius: 10px;
    }

    .modal-page {
        padding: 14px;
    }

    .esi-sheet-header,
    .esi-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    .esi-sheet-badge {
        min-width: 0;
        width: 100%;
        text-align: left;
    }

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

    .esi-main {
        border-right: none;
    }

    .esi-sidebar {
        border-top: 1px solid #d4d7c8;
    }

    .esi-field-grid,
    .esi-field-grid-compact,
    .esi-discipline-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .esi-section {
        padding: 14px;
    }

    .esi-sheet-header h2 {
        font-size: 22px;
    }
}
