/* ═══════════════════════════════════════════════════════════════ */
/* RESET & BASE                                                    */
/* ═══════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0f172a;
    color: #e2e8f0;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════ */
/* AUTH SCREENS                                                    */
/* ═══════════════════════════════════════════════════════════════ */

.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
}

.auth-card {
    background: #1e293b;
    padding: 40px;
    border-radius: 16px;
    width: 420px;
    max-width: 90vw;
    color: white;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.setup-card { width: 520px; }

.auth-logo {
    width: 56px; height: 56px;
    background: #dc2626;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 800; color: white;
    margin-bottom: 24px;
}

.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: #94a3b8; font-size: 14px; margin-bottom: 28px; }

.auth-error {
    background: #7f1d1d; border: 1px solid #dc2626;
    color: #fca5a5; padding: 10px 14px; border-radius: 8px;
    font-size: 14px; margin-bottom: 16px;
}

.step-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: #e2e8f0; }
.step-desc { font-size: 13px; color: #94a3b8; margin-bottom: 20px; line-height: 1.5; }
.setup-buttons { display: flex; gap: 10px; margin-top: 10px; }
.skip-link { text-align: center; margin-top: 16px; font-size: 13px; color: #64748b; cursor: pointer; text-decoration: underline; }
.skip-link:hover { color: #94a3b8; }

/* ═══════════════════════════════════════════════════════════════ */
/* FORMS                                                           */
/* ═══════════════════════════════════════════════════════════════ */

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block; font-size: 13px; font-weight: 500;
    color: #94a3b8; margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select {
    width: 100%; padding: 10px 14px;
    background: #0f172a; border: 1px solid #334155;
    border-radius: 8px; color: white; font-size: 14px;
    outline: none; transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus { border-color: #dc2626; }
.form-group input::placeholder { color: #475569; }

.form-group label:has(input[type="checkbox"]) {
    display: flex; align-items: center; gap: 8px; color: #e2e8f0; cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════ */
/* BUTTONS                                                         */
/* ═══════════════════════════════════════════════════════════════ */

.btn-primary {
    background: #dc2626; color: white; border: none;
    padding: 10px 20px; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: #b91c1c; }
.btn-primary:disabled { background: #64748b; cursor: not-allowed; }

.btn-secondary {
    background: #334155; color: #e2e8f0;
    border: 1px solid #475569; padding: 10px 20px;
    border-radius: 8px; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: background 0.2s;
}
.btn-secondary:hover { background: #475569; }
.btn-full { width: 100%; }

.btn-refresh {
    background: #334155; color: #e2e8f0;
    border: 1px solid #475569; padding: 8px 16px;
    border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn-refresh:hover { background: #475569; }
.btn-refresh:disabled { background: #1e293b; color: #475569; cursor: not-allowed; }

.btn-logout {
    background: none; border: 1px solid #475569;
    color: #94a3b8; padding: 6px 12px; border-radius: 6px;
    font-size: 12px; cursor: pointer; width: 100%;
}
.btn-logout:hover { background: #334155; color: white; }

.btn-table {
    background: none; border: 1px solid #475569;
    color: #94a3b8; padding: 4px 10px; border-radius: 4px;
    font-size: 12px; cursor: pointer; margin-right: 4px;
}
.btn-table:hover { background: #334155; color: white; }

.btn-danger-text { color: #f87171; border-color: #7f1d1d; }
.btn-danger-text:hover { background: #7f1d1d; color: #fca5a5; }

/* ═══════════════════════════════════════════════════════════════ */
/* LAYOUT                                                          */
/* ═══════════════════════════════════════════════════════════════ */

.layout { display: flex; height: 100vh; }

.sidebar {
    width: 240px; background: #0f172a; color: white;
    padding: 20px; display: flex; flex-direction: column;
    border-right: 1px solid #1e293b;
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }

.brand-icon {
    width: 36px; height: 36px; background: #dc2626;
    border-radius: 8px; display: flex; align-items: center;
    justify-content: center; font-weight: 800; font-size: 18px;
}

.sidebar-brand span { font-size: 16px; font-weight: 700; }
.sidebar-nav { flex: 1; }

.nav-link {
    display: flex; align-items: center; gap: 10px;
    color: #64748b; text-decoration: none;
    padding: 10px 12px; border-radius: 8px;
    margin-bottom: 4px; font-size: 14px; transition: all 0.15s;
}
.nav-link:hover { color: #e2e8f0; background: #1e293b; }
.nav-link.active { color: white; background: #1e293b; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { border-top: 1px solid #1e293b; padding-top: 16px; }
.user-info { font-size: 13px; color: #94a3b8; margin-bottom: 8px; }

.content {
    flex: 1; padding: 30px; overflow-y: auto;
    background: #0f172a; color: #e2e8f0;
}

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 24px; font-weight: 700; color: white; }

/* ═══════════════════════════════════════════════════════════════ */
/* DASHBOARD CARDS                                                 */
/* ═══════════════════════════════════════════════════════════════ */

.overview-cards { display: flex; gap: 20px; margin-bottom: 30px; }

.card {
    flex: 1; background: #1e293b; padding: 20px; border-radius: 12px;
    text-align: center; color: white; border: 1px solid #334155;
}
.card h3 { font-size: 13px; color: #94a3b8; font-weight: 500; margin-bottom: 8px; }
.card p { font-size: 24px; font-weight: 700; }

.grid { display: flex; gap: 20px; }

.panel {
    flex: 1; background: #1e293b; padding: 20px; border-radius: 12px;
    color: white; border: 1px solid #334155;
}
.panel h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════════ */
/* UNIFIED TABLE STYLES                                            */
/* ═══════════════════════════════════════════════════════════════ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #1e293b;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #334155;
}

.data-table thead { background: #0f172a; }

.data-table th {
    text-align: left;
    padding: 12px 14px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    border-bottom: 2px solid #334155;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    position: relative;
    transition: color 0.15s;
}

.data-table th:hover { color: #e2e8f0; }

.data-table th .sort-arrow {
    margin-left: 4px;
    font-size: 10px;
    color: #475569;
    transition: color 0.15s;
}

.data-table th.sort-asc .sort-arrow,
.data-table th.sort-desc .sort-arrow { color: #dc2626; }

.data-table th.sort-asc .sort-arrow::after { content: "▲"; }
.data-table th.sort-desc .sort-arrow::after { content: "▼"; }

.data-table th:not(.sort-asc):not(.sort-desc) .sort-arrow::after { content: "⇅"; }

/* Non-sortable headers */
.data-table th.no-sort { cursor: default; }
.data-table th.no-sort:hover { color: #64748b; }

.data-table td {
    padding: 11px 14px;
    border-bottom: 1px solid #1a2332;
    font-size: 13px;
    color: #cbd5e1;
}

.data-table tbody tr {
    transition: background 0.1s;
}

.data-table tbody tr:hover {
    background: #263248;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table .clickable-row { cursor: pointer; }
.data-table .clickable-row:hover { background: #334155; }

.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }

.danger { color: #f87171; font-weight: 600; }
.success-text { color: #4ade80; }
.muted { color: #64748b; }
.bold { font-weight: 600; color: #f1f5f9; }

/* Panel-level tables (inside panels, no extra border) */
.panel .data-table { border: none; background: transparent; }
.panel .data-table thead { background: transparent; }
.panel .data-table th { border-bottom: 1px solid #334155; }

/* Empty state */
.empty-row td {
    text-align: center;
    color: #475569;
    padding: 24px;
    font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════ */
/* LEGACY TABLE SUPPORT (for simple inline tables)                 */
/* ═══════════════════════════════════════════════════════════════ */

table:not(.data-table) { width: 100%; border-collapse: collapse; }
table:not(.data-table) th {
    text-align: left; padding: 10px; font-size: 12px;
    font-weight: 600; color: #94a3b8;
    border-bottom: 1px solid #334155;
    text-transform: uppercase; letter-spacing: 0.5px;
}
table:not(.data-table) td {
    padding: 10px; border-bottom: 1px solid #1e293b; font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════ */
/* TABS                                                            */
/* ═══════════════════════════════════════════════════════════════ */

.tabs { margin-bottom: 20px; display: flex; gap: 8px; }

.tab {
    padding: 8px 16px; border: 1px solid #334155;
    background: #1e293b; color: #94a3b8;
    cursor: pointer; border-radius: 6px; font-size: 13px;
    transition: all 0.15s;
}
.tab:hover { color: #e2e8f0; border-color: #475569; }
.tab.active { background: #dc2626; color: white; border-color: #dc2626; }

/* ═══════════════════════════════════════════════════════════════ */
/* MODAL                                                           */
/* ═══════════════════════════════════════════════════════════════ */

.modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-content {
    background: #1e293b; color: #e2e8f0;
    padding: 28px; width: 900px; max-width: 92vw;
    max-height: 85vh; border-radius: 14px;
    border: 1px solid #334155;
    display: flex; flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; padding-bottom: 16px;
    border-bottom: 1px solid #334155;
}

.modal-header h2 { font-size: 20px; font-weight: 700; color: white; }

.modal-close {
    background: none; border: none; color: #64748b;
    font-size: 24px; cursor: pointer; padding: 4px 8px;
    border-radius: 6px; transition: all 0.15s;
}
.modal-close:hover { color: white; background: #334155; }

.modal-body {
    flex: 1; overflow-y: auto;
    padding-right: 4px;
}

/* Customer Profile Sections */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.profile-card {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 16px;
}

.profile-card h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #64748b;
    font-weight: 700;
    margin-bottom: 10px;
}

.profile-card .big-number {
    font-size: 28px;
    font-weight: 700;
    color: white;
}

.profile-card .big-number.danger { color: #f87171; }

.profile-section {
    margin-bottom: 20px;
}

.profile-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #0f172a;
    font-size: 13px;
}

.contact-badge {
    background: #334155;
    color: #94a3b8;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    min-width: 50px;
    text-align: center;
}

.location-card {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
}

.location-card .loc-name { font-weight: 600; color: #e2e8f0; margin-bottom: 4px; }
.location-card .loc-addr { font-size: 13px; color: #94a3b8; }

/* ═══════════════════════════════════════════════════════════════ */
/* STATUS BADGES                                                   */
/* ═══════════════════════════════════════════════════════════════ */

.status-active {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600;
    background: #14532d; color: #4ade80; border: 1px solid #166534;
}

.status-inactive {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600;
    background: #44403c; color: #a8a29e; border: 1px solid #57534e;
}

.status-badge {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600;
}

.status-badge.open { background: #1e3a5f; color: #60a5fa; border: 1px solid #2563eb; }
.status-badge.completed { background: #14532d; color: #4ade80; border: 1px solid #166534; }
.status-badge.overdue { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }
.status-badge.default { background: #334155; color: #94a3b8; border: 1px solid #475569; }

/* ═══════════════════════════════════════════════════════════════ */
/* ADMIN / SETTINGS                                                */
/* ═══════════════════════════════════════════════════════════════ */

.settings-section { margin-bottom: 32px; }
.settings-section h2 { font-size: 18px; font-weight: 600; color: white; margin-bottom: 12px; }

.settings-card {
    background: #1e293b; border: 1px solid #334155;
    border-radius: 12px; padding: 24px;
}

.connection-badge {
    display: inline-block; padding: 6px 14px; border-radius: 20px;
    font-size: 13px; font-weight: 600; margin-bottom: 20px;
}
.connection-badge.connected { background: #14532d; color: #4ade80; border: 1px solid #166534; }
.connection-badge.disconnected { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }

.sync-info { font-size: 13px; color: #64748b; margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════════ */
/* AP VIEW                                                         */
/* ═══════════════════════════════════════════════════════════════ */

#apView .card { text-align: left; border: 1px solid #334155; }
#apView .card h3 { color: #e2e8f0; font-size: 16px; font-weight: 600; margin-bottom: 12px; }

#apView select, #apView input:not([type="checkbox"]) {
    padding: 8px 12px; background: #0f172a; border: 1px solid #334155;
    color: #e2e8f0; border-radius: 8px; font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════ */
/* TOAST                                                           */
/* ═══════════════════════════════════════════════════════════════ */

.toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 12px 20px; border-radius: 8px;
    font-size: 14px; font-weight: 500; z-index: 2000;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    animation-fill-mode: forwards;
}
.toast.success { background: #14532d; color: #4ade80; border: 1px solid #166534; }
.toast.error { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }

@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ═══════════════════════════════════════════════════════════════ */
/* SCROLLBAR                                                       */
/* ═══════════════════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }