/* ─────────────────────────────────────────────────────────────────────────
   Financial Statements Generator — Main Stylesheet
   ───────────────────────────────────────────────────────────────────────── */

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

:root {
    --blue:       #1a56db;
    --blue-dark:  #1341b0;
    --blue-light: #ebf2ff;
    --green:      #057a55;
    --green-bg:   #def7ec;
    --red:        #c81e1e;
    --red-bg:     #fde8e8;
    --amber:      #92400e;
    --amber-bg:   #fef3c7;
    --gray-50:    #f9fafb;
    --gray-100:   #f3f4f6;
    --gray-200:   #e5e7eb;
    --gray-300:   #d1d5db;
    --gray-500:   #6b7280;
    --gray-700:   #374151;
    --gray-900:   #111827;
    --radius:     8px;
    --radius-lg:  12px;
    --shadow-sm:  0 1px 2px 0 rgb(0 0 0 / .05);
    --shadow:     0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
    --shadow-md:  0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Container ───────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.navbar .container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.navbar-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gray-900);
    text-decoration: none;
}
.navbar-links { display: flex; gap: 1.5rem; }
.navbar-links a {
    font-size: .9rem;
    color: var(--gray-500);
    text-decoration: none;
    padding: .25rem 0;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.navbar-links a:hover,
.navbar-links a.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

/* ── Main / Footer ────────────────────────────────────────────────────────── */
.main-content { flex: 1; padding: 2rem 0; }
.footer {
    background: #fff;
    border-top: 1px solid var(--gray-200);
    padding: 1rem 0;
    text-align: center;
    font-size: .85rem;
    color: var(--gray-500);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: .9rem;
    font-weight: 500;
}
.alert-success { background: var(--green-bg); color: var(--green); }
.alert-error    { background: var(--red-bg);   color: var(--red);   }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-title    { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.page-subtitle { font-size: .9rem;  color: var(--gray-500); margin-top: .2rem; }
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
    text-decoration: none;
    background: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-ghost {
    color: var(--gray-700);
    border-color: var(--gray-300);
    background: #fff;
}
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger-ghost { color: var(--red); border-color: #fca5a5; background: #fff; }
.btn-danger-ghost:hover { background: var(--red-bg); }
.btn-lg { padding: .65rem 1.25rem; font-size: 1rem; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.inline-form { display: inline; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-section { padding: 1.5rem; margin-bottom: 1.25rem; }
.card-info    { padding: 1.25rem; }
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 1.25rem;
    padding-bottom: .6rem;
    border-bottom: 1px solid var(--gray-100);
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    padding: .75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: .8rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}
.table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }
.entity-name { font-weight: 500; }
.entity-reg  { font-size: .8rem; color: var(--gray-500); }
.mono { font-family: 'Courier New', monospace; font-size: .82rem; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .65rem;
    border-radius: 99px;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-type     { background: var(--blue-light); color: var(--blue-dark); }
.badge-queued   { background: var(--gray-100);   color: var(--gray-700);  }
.badge-processing { background: var(--amber-bg); color: var(--amber); }
.badge-completed { background: var(--green-bg);  color: var(--green);  }
.badge-failed   { background: var(--red-bg);     color: var(--red);    }

/* ── Status card ─────────────────────────────────────────────────────────── */
.status-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--gray-300);
}
.status-completed { border-left-color: var(--green); }
.status-failed    { border-left-color: var(--red); }
.status-processing,
.status-queued    { border-left-color: var(--blue); }
.status-icon svg  { display: block; }
.status-completed .status-icon svg { color: var(--green); }
.status-failed    .status-icon svg { color: var(--red);   }
.status-processing .status-icon,
.status-queued .status-icon       { color: var(--blue);  }
.status-title { font-size: 1.1rem; font-weight: 600; }
.status-meta  { font-size: .875rem; color: var(--gray-500); margin-top: .25rem; }
.status-error { font-size: .875rem; color: var(--red); margin-top: .25rem; }

/* ── Stats row ───────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.stat-label { font-size: .78rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .3rem; }
.stat-value { font-size: 1.1rem; font-weight: 600; }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }

/* ── Document grid ───────────────────────────────────────────────────────── */
.doc-grid { display: grid; gap: .75rem; }
.doc-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--gray-50);
}
.doc-icon { color: var(--blue); flex-shrink: 0; }
.doc-info { flex: 1; }
.doc-name { font-weight: 500; font-size: .9rem; }
.doc-size { font-size: .8rem; color: var(--gray-500); margin-top: .15rem; }
.doc-actions { display: flex; gap: .5rem; flex-shrink: 0; }

/* ── Detail list ─────────────────────────────────────────────────────────── */
.detail-list { display: grid; gap: 0; }
.detail-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 1rem;
    padding: .65rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: .9rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-row dt { font-weight: 500; color: var(--gray-500); }
.detail-row dd { color: var(--gray-900); }

/* ── Form layout ─────────────────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    align-items: start;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: .75rem;
}
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-label {
    font-size: .875rem;
    font-weight: 500;
    color: var(--gray-700);
}
.form-label.required::after { content: ' *'; color: var(--red); }
.form-hint { font-size: .8rem; color: var(--gray-500); font-weight: 400; }
.form-hint-below { font-size: .78rem; color: var(--gray-500); }
.form-control {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .9rem;
    color: var(--gray-900);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgb(26 86 219 / .15);
}
.form-control.is-invalid { border-color: var(--red); }
.form-error { font-size: .8rem; color: var(--red); margin-top: .2rem; }
select.form-control { appearance: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; padding-top: .5rem; }

/* ── Checkbox group ──────────────────────────────────────────────────────── */
.checkbox-group { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    cursor: pointer;
    padding: .5rem;
    border-radius: var(--radius);
}
.checkbox-label:hover { background: var(--gray-50); }
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }

/* ── Upload area ─────────────────────────────────────────────────────────── */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    background: var(--gray-50);
    position: relative;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.upload-area:hover,
.upload-area.drag-over { border-color: var(--blue); background: var(--blue-light); }
.upload-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.upload-ui { pointer-events: none; }
.upload-ui svg { margin: 0 auto .75rem; color: var(--gray-500); }
.upload-label { font-weight: 500; color: var(--gray-700); margin-bottom: .3rem; }
.upload-link  { color: var(--blue); }
.upload-hint  { font-size: .8rem; color: var(--gray-500); }
.upload-preview {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    color: var(--gray-700);
}
.upload-preview svg { color: var(--blue); flex-shrink: 0; }
.upload-clear {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 1rem;
    line-height: 1;
}
.upload-clear:hover { color: var(--red); }
.hidden { display: none !important; }

/* ── Validation panel ────────────────────────────────────────────────────── */
.validation-panel { margin-top: 1rem; }
.val-loading {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    color: var(--gray-500);
}
.val-block {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: .5rem;
}
.val-block ul { margin: .4rem 0 0 1.2rem; }
.val-block li { margin-bottom: .2rem; }
.val-ok      { background: var(--green-bg);  color: var(--green); }
.val-warning { background: var(--amber-bg);  color: var(--amber); }
.val-error   { background: var(--red-bg);    color: var(--red);   }
.val-stats   { margin-top: .4rem; display: flex; gap: 1rem; font-size: .82rem; opacity: .8; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.form-sidebar { position: sticky; top: 76px; }
.sidebar-title { font-weight: 600; font-size: .875rem; margin-bottom: .6rem; margin-top: 0; }
.sidebar-title.mt { margin-top: 1.25rem; }
.sidebar-text  { font-size: .82rem; color: var(--gray-500); margin-bottom: .6rem; }
.sidebar-list  { list-style: none; font-size: .82rem; display: grid; gap: .3rem; }
.sidebar-list li { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.sidebar-list code { font-size: .78rem; background: var(--gray-100); padding: .1rem .35rem; border-radius: 4px; }
.at-statement { color: var(--gray-500); font-size: .75rem; }
.mini-table { width: 100%; border-collapse: collapse; font-size: .82rem; margin-bottom: .5rem; }
.mini-table th { padding: .3rem .5rem; text-align: left; font-weight: 600; color: var(--gray-500); border-bottom: 1px solid var(--gray-200); }
.mini-table td { padding: .3rem .5rem; border-bottom: 1px solid var(--gray-100); }
.mini-table code { font-size: .76rem; background: var(--gray-100); padding: .05rem .3rem; border-radius: 3px; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray-500);
}
.empty-state svg { margin: 0 auto 1.25rem; }
.empty-state h3  { font-size: 1.1rem; font-weight: 600; color: var(--gray-900); margin-bottom: .4rem; }
.empty-state p   { margin-bottom: 1.5rem; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination-wrapper { display: flex; justify-content: flex-end; margin-top: 1rem; }
.pagination { display: flex; gap: .25rem; }
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    font-size: .875rem;
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
    background: #fff;
    text-decoration: none;
    transition: background .1s;
}
.page-btn:hover:not(.disabled):not(.active) { background: var(--gray-100); }
.page-btn.active  { background: var(--blue); color: #fff; border-color: var(--blue); }
.page-btn.disabled { color: var(--gray-300); cursor: not-allowed; }
.page-btn.dots { border: none; background: none; cursor: default; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
    .form-grid    { grid-template-columns: 1fr; }
    .form-sidebar { position: static; }
    .stats-row    { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .form-row       { grid-template-columns: 1fr; }
    .checkbox-group { grid-template-columns: 1fr; }
    .stats-row      { grid-template-columns: 1fr 1fr; }
    .detail-row     { grid-template-columns: 1fr; gap: .15rem; }
    .page-header    { flex-direction: column; }
    .table th, .table td { padding: .6rem .75rem; }
    .doc-card       { flex-wrap: wrap; }
}
