/* =========================================================
   Sales Tax Reconciliation – Application Stylesheet
   ========================================================= */

/* ----- CSS Variables ----- */
:root {
    --color-sidebar-bg:       #1e2a3a;
    --color-sidebar-text:     #94a3b8;
    --color-sidebar-active:   #3b82f6;
    --color-sidebar-hover:    #2d3f55;
    --color-sidebar-border:   #2d3f55;
    --color-sidebar-header:   #ffffff;

    --color-primary:          #3b82f6;
    --color-primary-hover:    #2563eb;
    --color-primary-text:     #ffffff;

    --color-danger:           #ef4444;
    --color-danger-hover:     #dc2626;
    --color-success:          #22c55e;
    --color-warning:          #f59e0b;

    --color-bg:               #f1f5f9;
    --color-surface:          #ffffff;
    --color-border:           #e2e8f0;
    --color-border-strong:    #cbd5e1;

    --color-text:             #1e293b;
    --color-text-muted:       #64748b;
    --color-text-faint:       #94a3b8;

    --header-height:          60px;
    --sidebar-width:          240px;

    --radius:                 6px;
    --radius-lg:              10px;
    --shadow-sm:              0 1px 3px rgba(0,0,0,.08);
    --shadow:                 0 2px 8px rgba(0,0,0,.10);

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;

    --transition: 150ms ease;
}

/* ----- Reset ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-sans); color: var(--color-text); line-height: 1.55; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }

/* =========================================================
   AUTH LAYOUT
   ========================================================= */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 24px 16px;
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -.3px;
}

.auth-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
    text-align: center;
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: 24px;
    font-size: .9rem;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* =========================================================
   APP LAYOUT
   ========================================================= */
.app-body { min-height: 100vh; background: var(--color-bg); }

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 8px 20px;
    border-bottom: 1px solid var(--color-sidebar-border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    background: var(--color-sidebar-bg);
}

.sidebar-logo {
    display: block;
    width: 200px;
    height: 52px;
    object-fit: cover;
    object-position: center;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--color-text-faint);
    padding: 12px 10px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius);
    color: var(--color-sidebar-text);
    font-size: .875rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
}

.nav-item:hover {
    background: var(--color-sidebar-hover);
    color: #ffffff;
    text-decoration: none;
}

.nav-item.active {
    background: var(--color-primary);
    color: #ffffff;
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .75;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

/* ----- Tenant Switcher ----- */
.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--color-sidebar-border);
    flex-shrink: 0;
}

.tenant-switcher { font-size: .8rem; }

.tenant-switcher-label {
    display: block;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--color-text-faint);
    margin-bottom: 4px;
    padding: 0 4px;
}

.tenant-switcher-current {
    font-weight: 600;
    color: #ffffff;
    padding: 4px;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tenant-switcher-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tenant-switch-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius);
    color: var(--color-sidebar-text);
    font-size: .8rem;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.tenant-switch-link:hover,
.tenant-switch-link.current {
    background: var(--color-sidebar-hover);
    color: #ffffff;
    text-decoration: none;
}

.tenant-code {
    font-size: .68rem;
    font-weight: 700;
    background: rgba(255,255,255,.12);
    border-radius: 3px;
    padding: 1px 5px;
    color: #fff;
    font-family: var(--font-mono);
}

/* ----- Main Area ----- */
.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ----- Header ----- */
.app-header {
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-tenant-badge {
    font-family: var(--font-mono);
    font-size: .75rem;
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
}

.header-tenant-name {
    font-weight: 600;
    color: var(--color-text);
    font-size: .9rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-user-name {
    font-size: .875rem;
    font-weight: 500;
    color: var(--color-text);
}

.logout-form { display: inline; }

.btn-logout {
    background: none;
    border: 1px solid var(--color-border-strong);
    color: var(--color-text-muted);
    border-radius: var(--radius);
    padding: 5px 12px;
    font-size: .8rem;
    transition: all var(--transition);
}

.btn-logout:hover {
    border-color: var(--color-danger);
    color: var(--color-danger);
}

/* ----- Content ----- */
.app-content {
    flex: 1;
    padding: 28px;
    max-width: 1200px;
    width: 100%;
}

/* =========================================================
   SHARED COMPONENTS
   ========================================================= */

/* Page Header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.page-subtitle {
    color: var(--color-text-muted);
    margin-top: 4px;
    font-size: .9rem;
}

/* Card */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}

.mt-4 { margin-top: 20px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

.btn-outline {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border-strong);
}
.btn-outline:hover { background: var(--color-bg); }

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-sm { padding: 5px 10px; font-size: .8rem; }

.btn-block { width: 100%; }

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table th {
    background: var(--color-bg);
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: #fafbfc; }

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

.table-empty {
    text-align: center;
    color: var(--color-text-muted);
    padding: 32px !important;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.badge-admin    { background: #dbeafe; color: #1d4ed8; }
.badge-system   { background: #f3e8ff; color: #7e22ce; }
.badge-you      { background: #dcfce7; color: #15803d; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: .78rem;
    font-weight: 600;
}

.status-active   { background: #dcfce7; color: #15803d; }
.status-inactive { background: #fee2e2; color: #b91c1c; }
.status-running  { background: #fef9c3; color: #a16207; }

.source-error {
    color: #b91c1c;
    font-size: .75rem;
    margin: 4px 0 0;
}

.source-error:empty { display: none; }

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: .78rem;
    font-weight: 600;
}

.role-admin { background: #dbeafe; color: #1d4ed8; }
.role-user  { background: #f1f5f9; color: #475569; }

.code-badge {
    font-family: var(--font-mono);
    font-size: .8rem;
    font-weight: 700;
    background: #f1f5f9;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 7px;
}

.env-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: .78rem; font-weight: 600; }
.env-sandbox    { background: #fef3c7; color: #92400e; }
.env-production { background: #dcfce7; color: #15803d; }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: .875rem;
    border: 1px solid transparent;
}

.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.error-list { margin-top: 6px; padding-left: 16px; list-style: disc; }
.error-list li { margin-top: 2px; }

/* Forms */
.form-card { padding: 0; }

.form-section {
    padding: 24px 28px;
    border-bottom: 1px solid var(--color-border);
}

.form-section:last-of-type { border-bottom: none; }

.form-section-title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 16px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px 28px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 16px;
}

.form-group:last-child { margin-bottom: 0; }

.form-group-inline { flex-direction: row; align-items: center; gap: 16px; margin-bottom: 16px; }
.form-group-inline .form-label { margin-bottom: 0; white-space: nowrap; }

.form-label {
    font-size: .835rem;
    font-weight: 600;
    color: var(--color-text);
}

.form-control {
    padding: 8px 11px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-hint {
    font-size: .78rem;
    color: var(--color-text-muted);
}

.required { color: var(--color-danger); margin-left: 1px; }

/* Toggle group (radio buttons styled) */
.toggle-group {
    display: flex;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    overflow: hidden;
    width: fit-content;
}

.toggle-option {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.toggle-option input[type="radio"] { display: none; }

.toggle-option span {
    display: block;
    padding: 7px 16px;
    font-size: .835rem;
    font-weight: 500;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-strong);
    transition: all var(--transition);
    user-select: none;
}

.toggle-option:last-child span { border-right: none; }

.toggle-option input[type="radio"]:checked + span {
    background: var(--color-primary);
    color: #fff;
}

/* Checkbox Grid (tenant/user assignment) */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.checkbox-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--color-surface);
    position: relative;
}

.checkbox-card input[type="checkbox"] {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.checkbox-card:hover { border-color: var(--color-primary); background: #eff6ff; }

.checkbox-card:has(input:checked) {
    border-color: var(--color-primary);
    background: #eff6ff;
}

.checkbox-card-inactive { opacity: .6; }

.checkbox-card-code {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--color-primary);
}

.checkbox-card-name {
    font-size: .85rem;
    font-weight: 500;
    color: var(--color-text);
    padding-right: 20px;
}

.checkbox-card-tag {
    font-size: .7rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 4px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--color-text);
    line-height: 1;
}

.stat-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.stat-sub {
    font-size: .78rem;
    color: var(--color-text-faint);
    margin-top: 2px;
}

/* Tenant Card Grid (non-admin dashboard) */
.tenant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    padding: 20px;
}

.tenant-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    transition: all var(--transition);
    background: var(--color-surface);
    text-align: center;
}

.tenant-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 4px 16px rgba(59,130,246,.15);
    transform: translateY(-2px);
    text-decoration: none;
}

.tenant-card-code {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-primary);
    letter-spacing: -1px;
}

.tenant-card-name {
    font-size: .875rem;
    font-weight: 500;
    color: var(--color-text);
    margin-top: 6px;
}

.tenant-card-action {
    font-size: .78rem;
    color: var(--color-text-faint);
    margin-top: 10px;
}

/* Empty state */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-muted);
}

/* Error pages */
.error-card { text-align: center; }

.error-code {
    font-size: 4rem;
    font-weight: 900;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: 12px;
}

.error-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.error-message {
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* Utility */
.text-muted { color: var(--color-text-muted); font-size: .875rem; }
.mb-4 { margin-bottom: 20px; }
.mt-2 { margin-top: 8px; }

/* =========================================================
   RECONCILIATION
   ========================================================= */
.recon-source-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 4px;
}

.source-card { padding: 20px; }

.source-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.source-label {
    font-weight: 600;
    font-size: .9rem;
    color: var(--color-text);
}

.source-timestamp {
    font-size: .78rem;
    color: var(--color-text-muted);
    margin: 2px 0;
}

.source-sub-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.source-sub-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--color-text-muted);
    display: block;
    margin-bottom: 4px;
}

.file-input {
    display: block;
    width: 100%;
    font-size: .8rem;
    color: var(--color-text-muted);
}

.source-sub-divider {
    text-align: center;
    font-size: .75rem;
    color: var(--color-text-muted);
    margin: 8px 0 0;
    position: relative;
}
.source-sub-divider::before,
.source-sub-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: var(--color-border);
}
.source-sub-divider::before { left: 0; }
.source-sub-divider::after  { right: 0; }

/* Report tabs */
.report-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: -1px;
}

.tab-btn {
    padding: 8px 16px;
    font-size: .835rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--color-bg);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover { background: var(--color-surface); color: var(--color-text); }

.tab-btn.active {
    background: var(--color-surface);
    color: var(--color-primary);
    border-color: var(--color-border);
    font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Table helpers */
.table-sm td, .table-sm th { padding: 8px 12px; font-size: .82rem; }
.num { text-align: right; font-family: var(--font-mono); font-size: .82rem; }
.table-scroll { overflow-x: auto; }
.row-warn td { background: #fff8f0 !important; }
.var-nonzero { color: var(--color-danger); font-weight: 600; }
.var-zero    { color: var(--color-success); font-weight: 600; }
.table-totals td { background: var(--color-bg); border-top: 2px solid var(--color-border-strong); }

/* =========================================================
   RECONCILIATION SUMMARY TAB
   ========================================================= */
.recon-sheet {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}
.recon-sheet th {
    padding: 7px 16px;
    background: var(--color-bg);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--color-text-muted);
    border-bottom: 2px solid var(--color-border-strong);
}
.recon-sheet td { padding: 5px 16px; border-bottom: 1px solid var(--color-border); }

.rs-section-row td {
    padding: 8px 16px 5px;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--color-text-muted);
    background: var(--color-bg);
    border-top: 2px solid var(--color-border-strong);
    border-bottom: 1px solid var(--color-border-strong);
}
.rs-variance-row td {
    background: #f8fafc;
    border-top: 1px solid var(--color-border-strong);
    border-bottom: 1px solid var(--color-border-strong);
}
.rs-subtotal-row td {
    border-bottom: 2px solid var(--color-border-strong);
}
.rs-group-row td {
    padding: 6px 16px 4px;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: none;
}
.rs-group-add  td { color: #166534; background: #f0fdf4; }
.rs-group-less td { color: #991b1b; background: #fef2f2; }
.rs-add-row  td { background: #f0fdf4; }
.rs-less-row td { background: #fef2f2; }
.rs-total-row td {
    padding: 8px 16px;
    background: #1e2a3a;
    color: #fff;
    font-size: .85rem;
    border-top: 3px solid var(--color-border-strong);
    border-bottom: none;
}
.rs-total-row .var-nonzero { color: #fca5a5; }
.rs-total-row .var-zero    { color: #86efac; }
