/* JT Law Firm - Document Management System */
/* Prevent FOUC: hide page until CSS is fully loaded */
html { opacity: 0; }

:root {
    --primary: #1a3a5c;
    --primary-light: #2a5a8c;
    --primary-dark: #0d1f33;
    --accent: #c8a45a;
    --accent-light: #e0c882;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #f57c00;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #eeeeee;
    --gray-300: #e0e0e0;
    --gray-400: #bdbdbd;
    --gray-500: #9e9e9e;
    --gray-600: #757575;
    --gray-700: #616161;
    --gray-800: #424242;
    --gray-900: #212121;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 8px;
    --sidebar-width: 240px;
}

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

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
}

.login-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    margin: 20px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 28px;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: -0.5px;
}

.login-logo .tagline {
    color: var(--gray-500);
    font-size: 14px;
    margin-top: 4px;
}

/* ============ SIDEBAR (Desktop) ============ */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    overflow-y: auto;
}

.navbar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.navbar-logo {
    max-width: 100%;
    height: 40px;
    width: auto;
}

.navbar-brand .accent {
    color: var(--accent);
}

.navbar-nav {
    list-style: none;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.navbar-nav a {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    display: block;
}

.navbar-nav a:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.navbar-nav a.active {
    color: white;
    background: rgba(255,255,255,0.18);
    font-weight: 600;
}

.navbar-user {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.navbar-user .user-name {
    font-size: 13px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-logout { display: none; }

.menu-toggle { display: none; }

/* Main Content - offset by sidebar */
.main-content {
    margin-left: var(--sidebar-width);
    max-width: 1100px;
    padding: 28px 32px;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: visible;
}

.card-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary);
}

.card-body {
    padding: 24px;
}

/* Status Cards Row */
.status-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.status-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
    border-top: 4px solid var(--primary);
}

.status-card.connected { border-top-color: var(--success); }
.status-card.disconnected { border-top-color: var(--danger); }
.status-card.warning { border-top-color: var(--warning); }

.status-card .status-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.status-card .status-label {
    font-size: 13px;
    color: var(--gray-600);
    margin-top: 4px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-300);
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group select {
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #388e3c; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #d32f2f; }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error { background: #ffebee; color: var(--danger); border: 1px solid #ef9a9a; }
.alert-success { background: #e8f5e9; color: var(--success); border: 1px solid #a5d6a7; }
.alert-warning { background: #fff3e0; color: var(--warning); border: 1px solid #ffcc80; }
.alert-info { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }

/* Tables */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead { background: var(--gray-50); }

th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--gray-200);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
    font-size: 14px;
}

tr:hover { background: var(--gray-50); }

/* Badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: #e8f5e9; color: var(--success); }
.badge-danger { background: #ffebee; color: var(--danger); }
.badge-warning { background: #fff3e0; color: var(--warning); }
.badge-info { background: #e3f2fd; color: #1565c0; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    color: var(--primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.4;
}

/* ============ RESPONSIVE - TABLET ============ */
@media (max-width: 768px) {
    .navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 56px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
        overflow: visible;
    }

    .navbar-brand {
        padding: 0;
        border-bottom: none;
    }

    .navbar-logo {
    max-width: 100%;
        height: 36px;
    }

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255,255,255,0.15);
        border: 2px solid rgba(255,255,255,0.3);
        color: white;
        font-size: 26px;
        cursor: pointer;
        width: 44px;
        height: 40px;
        padding: 0;
        border-radius: 8px;
        line-height: 1;
        transition: background 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    .menu-toggle:hover, .menu-toggle:active {
        background: rgba(255,255,255,0.25);
    }

    .navbar-nav {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--primary);
        flex-direction: column;
        padding: 12px;
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        overflow-y: auto;
        z-index: 200;
        gap: 2px;
    }

    .navbar-nav.open { display: flex; }

    .navbar-nav li { width: 100%; }

    .navbar-nav a {
        padding: 14px 16px;
        width: 100%;
        display: block;
        font-size: 16px;
        border-radius: 8px;
    }

    .navbar-nav a.active {
        background: rgba(255,255,255,0.2);
    }

    .navbar-user { display: none; }

    .nav-logout {
        display: block;
        margin-top: 8px;
        border-top: 1px solid rgba(255,255,255,0.15);
        padding-top: 8px;
    }

    .nav-logout a {
        color: rgba(255,255,255,0.7) !important;
    }

    .main-content {
        margin-left: 0;
        padding: 68px 12px 12px;
    }

    .form-row { grid-template-columns: 1fr; }

    .card-header { padding: 12px 16px; }
    .card-header h2 { font-size: 16px; }
    .card-body { padding: 16px; }

    th, td { padding: 10px 12px; font-size: 13px; }

    .login-container { padding: 32px 24px; }

    .modal { margin: 10px; max-height: 85vh; }

    .status-card .status-value { font-size: 22px; }
    .status-card { padding: 14px; }

    .empty-state { padding: 32px 16px; }
}

/* ============ RESPONSIVE - PHONE ============ */
@media (max-width: 480px) {
    .navbar {
        height: 52px;
        padding: 0 10px;
    }

    .navbar-logo {
    max-width: 100%; height: 30px; }

    .navbar-nav { top: 52px; }

    .menu-toggle {
        width: 42px;
        height: 38px;
        font-size: 24px;
    }

    .main-content { padding: 62px 8px 8px; }

    .card { border-radius: 6px; margin-bottom: 12px; }
    .card-header { padding: 10px 12px; }
    .card-header h2 { font-size: 15px; }
    .card-body { padding: 12px; }

    .status-row { grid-template-columns: 1fr; gap: 8px; }

    .btn { padding: 10px 16px; font-size: 14px; }
    .btn-sm { padding: 8px 12px; font-size: 13px; }

    th, td { padding: 8px 10px; font-size: 13px; }

    .form-group select {
        -webkit-appearance: none;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px;
        font-size: 16px;
    }

    .alert { font-size: 13px; padding: 10px 12px; }
}

/* Reveal page after CSS is loaded */
html { opacity: 1; }
