/* ══════════════════════════════════════════════
   Aphias Capital — Legal Document Review
   ══════════════════════════════════════════════ */

:root {
    --bg: #F0F2F5;
    --bg-card: #FFFFFF;
    --bg-hover: #E8EBF0;
    --bg-input: #FFFFFF;
    --border: #D0D4DC;
    --text: #1A1A1A;
    --text2: #444444;
    --muted: #6B7280;
    --blue: #0066CC;
    --blue-light: #DBEAFE;
    --green: #16A34A;
    --green-light: #D1FAE5;
    --red: #DC2626;
    --red-light: #FEE2E2;
    --orange: #D97706;
    --orange-light: #FEF3C7;
    --purple: #7C3AED;
    --purple-light: #EDE9FE;
    --topbar-bg: #1A1A2E;
    --sidebar-bg: #1A1A2E;
    --sidebar-hover: #2A2A40;
    --sidebar-active: #3B82F6;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Topbar ── */
.topbar {
    height: 48px;
    background: var(--topbar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 200;
}
.topbar-left { display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; flex: 1; }
.topbar-logo-img { height: 28px; width: auto; max-width: 120px; margin-right: 8px; object-fit: contain; flex-shrink: 0; }
.topbar-sub { color: #A0A8B8; font-size: 11px; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-status { color: var(--green); font-size: 8px; }
.topbar-user { color: #A0A8B8; font-size: 12px; }
.topbar-role { opacity: 0.6; }
.topbar-logout {
    color: #A0A8B8; text-decoration: none; font-size: 16px;
    margin-left: 12px; opacity: 0.6; transition: opacity 0.2s;
}
.topbar-logout:hover { opacity: 1; }

/* ── Hamburger ── */
.hamburger {
    display: none; background: none; border: none; cursor: pointer;
    padding: 4px; flex-direction: column; gap: 4px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: #A0A8B8; border-radius: 2px; }
@media (max-width: 900px) { .hamburger { display: flex; } }

/* ── Layout ── */
.app-body {
    display: flex;
    margin-top: 48px;
    min-height: calc(100vh - 48px);
}

/* ── Sidebar ── */
.sidebar {
    width: 200px;
    min-width: 200px;
    background: var(--sidebar-bg);
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 48px;
    bottom: 0;
    overflow-y: auto;
    transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #CCCCDD;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-item:hover { background: var(--sidebar-hover); color: #FFF; }
.nav-item.active { background: var(--sidebar-active); color: #FFF; font-weight: 600; }
.nav-icon { font-size: 15px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-section {
    padding: 20px 20px 6px;
    color: #666680;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* ── Sidebar collapse (desktop) ── */
.sidebar-collapsed .sidebar { width: 52px; min-width: 52px; padding: 12px 0; }
.sidebar-collapsed .nav-item { padding: 10px 16px; justify-content: center; }
.sidebar-collapsed .nav-item span:not(.nav-icon) { display: none; }
.sidebar-collapsed .nav-section { display: none; }
.sidebar-collapsed .content { margin-left: 52px; }

/* ── Content ── */
.content {
    flex: 1;
    margin-left: 200px;
    padding: 24px;
    transition: margin-left 0.25s ease;
}

/* ── Mobile ── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 150;
        position: fixed;
    }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed; inset: 0; background: rgba(0,0,0,0.4);
        z-index: 140; display: none;
    }
    .sidebar-open .sidebar-overlay { display: block; }
    .content { margin-left: 0; }
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--blue); color: #FFF; border-color: var(--blue); }
.btn-primary:hover { background: #0055AA; }
.btn-danger { background: var(--red); color: #FFF; border-color: var(--red); }
.btn-danger:hover { background: #B91C1C; }
.btn-success { background: var(--green); color: #FFF; border-color: var(--green); }
.btn-success:hover { background: #15803D; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
th {
    font-weight: 600;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #F8F9FA;
}
tr:hover td { background: #F8FAFC; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 4px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg-input);
    transition: border-color 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { cursor: pointer; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
}
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-gray { background: #F1F5F9; color: #475569; }

/* ── Flash Messages ── */
.flash-container { margin-bottom: 16px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 8px;
}
.flash-success { background: var(--green-light); color: #166534; border: 1px solid #86EFAC; }
.flash-error { background: var(--red-light); color: #991B1B; border: 1px solid #FCA5A5; }
.flash-info { background: var(--blue-light); color: #1E40AF; border: 1px solid #93C5FD; }
.flash-warning { background: var(--orange-light); color: #92400E; border: 1px solid #FCD34D; }

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Login Page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1A1A2E 0%, #16213E 100%);
}
.login-box {
    background: #FFF;
    border-radius: 12px;
    padding: 40px 36px;
    text-align: center;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo-img { height: 80px; width: auto; margin-bottom: 8px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #FFF;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.login-btn:hover { background: #F8F9FA; }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}
.tab {
    padding: 10px 18px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab .tab-count {
    background: #E8EBF0;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 6px;
}
.tab.active .tab-count { background: var(--blue-light); }

/* ── Document Upload Zone ── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #FAFBFC;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--blue);
    background: var(--blue-light);
}
.upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-text { font-size: 14px; color: var(--text2); }
.upload-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Playbook Sections ── */
.playbook-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}
.playbook-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #F8F9FA;
    cursor: pointer;
    user-select: none;
}
.playbook-header:hover { background: #F0F2F5; }
.playbook-toggle { font-size: 12px; color: var(--muted); transition: transform 0.2s; }
.playbook-body { padding: 16px; display: none; }
.playbook-section.open .playbook-body { display: block; }
.playbook-section.open .playbook-toggle { transform: rotate(90deg); }

.playbook-row {
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #F0F2F5;
    font-size: 13px;
}
.playbook-row:last-child { border-bottom: none; }
.playbook-issue { font-weight: 600; color: var(--text); }
.playbook-preferred { color: var(--text2); }
.playbook-fallback { color: var(--muted); }

/* ── Review Panel ── */
.review-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 1100px) { .review-panel { grid-template-columns: 1fr; } }

.review-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.review-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.review-clause { font-weight: 600; font-size: 14px; }
.review-original, .review-revised {
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 8px;
}
.review-original { background: #FEF2F2; border-left: 3px solid var(--red); }
.review-revised { background: #F0FDF4; border-left: 3px solid var(--green); }
.review-comment {
    font-size: 12px;
    color: var(--muted);
    padding: 8px 12px;
    background: #F8F9FA;
    border-radius: 4px;
    border-left: 3px solid var(--blue);
}

/* ── Progress / Processing ── */
.processing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--blue-light);
    border: 1px solid #93C5FD;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.spinner {
    width: 20px; height: 20px;
    border: 2px solid #93C5FD;
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Timeline ── */
.timeline { position: relative; padding-left: 20px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 7px; top: 4px; bottom: 4px;
    width: 2px;
    background: var(--border);
}
.timeline-item { padding: 8px 0 16px 16px; position: relative; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -17px; top: 12px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--blue);
    border: 2px solid var(--bg-card);
}
.timeline-item.complete::before { background: var(--green); }
.timeline-item.error::before { background: var(--red); }
.timeline-time { font-size: 11px; color: var(--muted); }
.timeline-text { font-size: 13px; }

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── Diff View ── */
.diff-add { background: #D1FAE5; color: #166534; }
.diff-del { background: #FEE2E2; color: #991B1B; text-decoration: line-through; }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text2); margin-bottom: 4px; }
.empty-text { font-size: 13px; }

/* ── Utility ── */
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
