/* ----------------------------------------------------------------
   Reset & base
---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: #1a1a2e;
    background: #f4f6f9;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .75rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 1rem; }

/* ----------------------------------------------------------------
   Sidebar
---------------------------------------------------------------- */
.sidebar {
    width: 220px;
    background: #1a1a2e;
    color: #c8cfe0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 200;
    transition: transform .25s ease;
}

.sidebar-brand {
    padding: 1.1rem 1rem .9rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand span { color: #60a5fa; }

.sidebar-nav { flex: 1; padding: .5rem 0; }

.nav-section {
    padding: .75rem 1rem .2rem;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6b7a99;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: .55rem 1rem;
    color: #c8cfe0;
    font-size: .9rem;
    transition: background .15s, color .15s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,.07);
    color: #fff;
    text-decoration: none;
}

.sidebar-nav a.active {
    border-left: 3px solid #60a5fa;
    padding-left: calc(1rem - 3px);
}

.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .85rem;
    color: #6b7a99;
}

.sidebar-footer strong { display: block; color: #c8cfe0; margin-bottom: .15rem; }
.sidebar-footer a { color: #6b7a99; font-size: .85rem; }
.sidebar-footer a:hover { color: #c8cfe0; }

/* Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 150;
}

/* ----------------------------------------------------------------
   Topbar
---------------------------------------------------------------- */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: .75rem 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem;
    color: #374151;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1a1a2e;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    font-size: .85rem;
    color: #6b7280;
    white-space: nowrap;
}

.topbar-notice {
    font-size: .78rem;
    font-weight: 500;
    color: #713f12;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    padding: .2rem .6rem;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ----------------------------------------------------------------
   Layout
---------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }

.main {
    margin-left: 220px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.content { padding: 1.25rem; flex: 1; }

/* ----------------------------------------------------------------
   Cards
---------------------------------------------------------------- */
.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: .625rem;
    border-bottom: 1px solid #f0f0f0;
}

/* ----------------------------------------------------------------
   Flash messages
---------------------------------------------------------------- */
.flash {
    border-radius: 6px;
    padding: .75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: .9rem;
}

.flash-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.flash-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.flash-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.flash-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }

.system-notice {
    background: #fefce8;
    border: 1px solid #fde047;
    border-radius: 6px;
    color: #713f12;
    font-size: .9rem;
    padding: .7rem 1rem;
    margin-bottom: 1.25rem;
}
.system-notice--standalone {
    margin: 1rem auto;
    max-width: 420px;
}

/* ----------------------------------------------------------------
   Buttons
---------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .375rem;
    padding: .6rem 1.1rem;
    border-radius: 6px;
    font-size: .9375rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    line-height: 1.4;
    transition: background .15s, border-color .15s;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover { text-decoration: none; }
.btn-block { width: 100%; }

.btn-primary   { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover { background: #f9fafb; }

.btn-danger    { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-lg { padding: .85rem 1.5rem; font-size: 1.05rem; }

/* ----------------------------------------------------------------
   Forms  — large touch targets throughout
---------------------------------------------------------------- */
.form-group { margin-bottom: 1.1rem; }

.form-label {
    display: block;
    font-size: .9rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: .4rem;
}

.form-label .required { color: #dc2626; margin-left: .15rem; }

.form-control {
    display: block;
    width: 100%;
    padding: .65rem .85rem;
    font-size: 1rem;           /* 16px prevents iOS zoom */
    line-height: 1.5;
    color: #1a1a2e;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
    -webkit-appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

textarea.form-control { resize: vertical; min-height: 90px; }

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .85rem center;
    padding-right: 2.25rem;
}

.form-hint  { font-size: .85rem; color: #6b7280; margin-top: .3rem; }
.form-error { font-size: .85rem; color: #dc2626; margin-top: .3rem; }
.form-control.is-invalid { border-color: #dc2626; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0 1rem;
}

/* Radio / checkbox groups */
.radio-group, .check-group {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem .9rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    font-size: .9375rem;
    transition: border-color .15s, background .15s;
}

.radio-option input { width: 1.1rem; height: 1.1rem; flex-shrink: 0; }
.radio-option:has(input:checked) { border-color: #2563eb; background: #eff6ff; }

/* File input */
.file-input-wrap {
    display: block;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.file-input-wrap .file-input-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
}

.file-input-wrap:hover { border-color: #2563eb; background: #f8faff; }
.file-input-wrap input[type=file] { display: none; }
.file-input-wrap .file-hint { font-size: .875rem; color: #6b7280; margin-top: .35rem; }

.file-list { margin-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }

.file-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .45rem .75rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: .875rem;
}

.file-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { color: #9ca3af; font-size: .8rem; white-space: nowrap; }
.file-item-remove {
    background: none; border: none; cursor: pointer; color: #9ca3af;
    padding: 0; line-height: 1; font-size: 1.1rem; flex-shrink: 0;
}
.file-item-remove:hover { color: #dc2626; }

/* ----------------------------------------------------------------
   Tables (desktop; becomes cards on mobile)
---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

th {
    text-align: left;
    font-weight: 600;
    padding: .6rem .75rem;
    border-bottom: 2px solid #e5e7eb;
    color: #374151;
    white-space: nowrap;
}

td {
    padding: .6rem .75rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

/* ----------------------------------------------------------------
   Info list (key–value pairs, not a data table)
---------------------------------------------------------------- */
.info-list { margin: 0; padding: 0; }
.info-row {
    display: flex;
    gap: 1rem;
    padding: .55rem 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: .9375rem;
}
.info-row:last-child { border-bottom: none; }
.info-label { flex: 0 0 40%; color: #6b7280; font-weight: 500; }

/* ----------------------------------------------------------------
   Badges
---------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-draft                { background: #f3f4f6; color: #6b7280; }
.badge-pending              { background: #fef9c3; color: #854d0e; }
.badge-approved             { background: #dcfce7; color: #166534; }
.badge-rejected             { background: #fee2e2; color: #991b1b; }
.badge-payment_file_created { background: #dbeafe; color: #1e40af; }
.badge-reconciled           { background: #d1fae5; color: #065f46; }

/* ----------------------------------------------------------------
   Page header
---------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.page-header h1 { margin-bottom: 0; }

/* ----------------------------------------------------------------
   Utility
---------------------------------------------------------------- */
.text-muted   { color: #6b7280; }
.text-right   { text-align: right; }
.text-danger  { color: #dc2626; }
.text-success { color: #16a34a; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ----------------------------------------------------------------
   Login page
---------------------------------------------------------------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f6f9;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 380px;
}

.login-card h1 { font-size: 1.4rem; margin-bottom: .2rem; }
.login-card .subtitle { color: #6b7280; font-size: .9rem; margin-bottom: 1.5rem; }

/* ----------------------------------------------------------------
   Mobile  (≤ 640px)
---------------------------------------------------------------- */
@media (max-width: 640px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-overlay.is-open {
        display: block;
    }

    .topbar-menu-btn {
        display: flex;
    }

    .main {
        margin-left: 0;
    }

    .content {
        padding: 1rem;
    }

    /* Stack form rows on mobile */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Full-width primary actions */
    .btn-mobile-block {
        width: 100%;
    }

    /* Table → stacked cards on small screens */
    .table-cards thead { display: none; }
    .table-cards tr {
        display: block;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        margin-bottom: .75rem;
        background: #fff;
        padding: .5rem .75rem;
    }
    .table-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: .35rem 0;
        border-bottom: 1px solid #f3f4f6;
        font-size: .9rem;
    }
    .table-cards td:last-child { border-bottom: none; }
    .table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #374151;
        font-size: .8rem;
        flex-shrink: 0;
        margin-right: .5rem;
    }
}

/* ------------------------------------------------------------------ */
/* Action bar                                                           */
/* ------------------------------------------------------------------ */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 220px;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 8px rgba(0,0,0,.06);
    padding: .75rem 1.5rem;
}

.action-bar-spacer { height: 5rem; }

@media (max-width: 640px) {
    .action-bar { left: 0; padding: .75rem 1rem; }
}

/* ------------------------------------------------------------------ */
/* Modal                                                                */
/* ------------------------------------------------------------------ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
    padding: 0;
}
.modal-close:hover { color: #111; }

.modal-body { padding: 1.25rem; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid #e5e7eb;
}

/* ------------------------------------------------------------------ */
/* Submission progress bar                                              */
/* ------------------------------------------------------------------ */
.progress-steps { display:flex; align-items:flex-start; gap:0; margin-bottom:1.25rem; }
.progress-step  { flex:1; display:flex; flex-direction:column; align-items:center; position:relative; }

.progress-step:not(:last-child)::after {
    content:''; position:absolute;
    top:12px; left:50%; width:100%; height:2px;
    background:#e5e7eb; z-index:0;
}
.progress-step.done:not(:last-child)::after { background:#16a34a; }

.progress-step-dot {
    width:24px; height:24px; border-radius:50%; border:2px solid #e5e7eb;
    background:#fff; z-index:1; display:flex; align-items:center; justify-content:center;
    font-size:.7rem; font-weight:700; color:#9ca3af;
}
.progress-step.done   .progress-step-dot { background:#16a34a; border-color:#16a34a; color:#fff; }
.progress-step.active .progress-step-dot { background:#2563eb; border-color:#2563eb; color:#fff; }

.progress-step-label {
    margin-top:.35rem; font-size:.72rem; font-weight:500;
    color:#9ca3af; text-align:center; line-height:1.2;
}
.progress-step.done   .progress-step-label { color:#16a34a; }
.progress-step.active .progress-step-label { color:#2563eb; }

.progress-step-rejected {
    margin-top:.2rem; font-size:.68rem; font-weight:600;
    color:#991b1b; background:#fee2e2; border-radius:999px;
    padding:.1rem .45rem;
}
