/**
 * TD Roots Admin Dashboard Styles
 */

/* ========================================
   CSS Variables
   ======================================== */
:root {
    /* Brand Colors */
    --primary: #376F86;
    --primary-dark: #2a5768;
    --primary-light: #4a8da8;
    --secondary: #E8F4F8;

    /* Neutrals */
    --text: #1F2933;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;
    --bg: #F9FAFB;
    --bg-white: #ffffff;
    --bg-dark: #1F2933;
    --border: #E5E7EB;

    /* Status */
    --success: #10B981;
    --success-bg: #D1FAE5;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;
    --error: #EF4444;
    --error-bg: #FEE2E2;
    --info: #3B82F6;
    --info-bg: #DBEAFE;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Layout */
    --header-height: 60px;
    --sidebar-width: 240px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition: 0.2s ease;
}

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

body {
    font-family: var(--font-family);
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 0.625rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--secondary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
}

.btn-block {
    width: 100%;
}

/* ========================================
   Auth Screens
   ======================================== */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.auth-container {
    text-align: center;
    padding: var(--space-2xl);
    max-width: 400px;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin-bottom: var(--space-lg);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.auth-subtitle {
    color: var(--text-muted);
    margin-bottom: var(--space-xl);
}

.auth-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-lg);
    border-radius: 50%;
    font-size: 2rem;
}

.auth-icon-error {
    background: var(--error-bg);
    color: var(--error);
}

/* Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-lg);
}

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

/* ========================================
   Admin App Layout
   ======================================== */
.admin-app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    min-height: 100vh;
}

/* Header */
.admin-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.header-logo {
    width: 32px;
    height: 32px;
}

.header-title {
    font-weight: 600;
    color: var(--text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.user-name {
    font-size: 0.875rem;
    color: var(--text-muted);
}

#sidebar-toggle {
    display: none;
}

/* Sidebar */
.admin-sidebar {
    grid-row: 2;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    padding: var(--space-lg) 0;
    overflow-y: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: 0 var(--space-md);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--secondary);
    color: var(--primary);
}

.nav-item.active {
    background: var(--secondary);
    color: var(--primary);
    font-weight: 500;
}

.nav-item i {
    font-size: 1.125rem;
}

/* Main Content */
.admin-main {
    grid-column: 2;
    grid-row: 2;
    padding: var(--space-xl);
    overflow-y: auto;
}

/* ========================================
   Pages
   ======================================== */
.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* ========================================
   Stats Cards
   ======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border);
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    font-size: 1.25rem;
}

.stat-icon.users {
    background: var(--info-bg);
    color: var(--info);
}

.stat-icon.receipts {
    background: var(--success-bg);
    color: var(--success);
}

.stat-icon.clients {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-icon.active {
    background: var(--secondary);
    color: var(--primary);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-lg);
    padding: var(--space-lg);
}

.card-description {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ========================================
   Sections
   ======================================== */
.dashboard-section,
.settings-section {
    margin-bottom: var(--space-2xl);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
}

/* ========================================
   Tables
   ======================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg);
}

.data-table tbody tr:hover {
    background: var(--bg);
}

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

.table-loading {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-2xl) !important;
}

.user-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-email {
    font-weight: 500;
}

.user-name-sub {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ========================================
   Pagination
   ======================================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
}

.page-info {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ========================================
   Search Box
   ======================================== */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: var(--space-md);
    color: var(--text-muted);
}

.search-box input {
    padding: var(--space-sm) var(--space-md) var(--space-sm) 2.5rem;
    font-family: inherit;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    width: 250px;
    transition: border-color var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ========================================
   Info Rows
   ======================================== */
.info-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.info-value {
    font-weight: 500;
    font-family: monospace;
}

/* ========================================
   Import Page
   ======================================== */
.import-section {
    max-width: 700px;
}

.import-section .card {
    padding: var(--space-xl);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.card-description {
    margin-bottom: var(--space-xl);
}

/* Form Elements */
.form-group {
    margin-bottom: var(--space-xl);
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-sm);
}

.form-control {
    width: 100%;
    padding: var(--space-md);
    font-family: inherit;
    font-size: 0.9375rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    background: var(--bg-white);
    transition: border-color var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

/* File Upload */
.file-upload-area {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--border-radius-lg);
    padding: var(--space-2xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--primary);
    background: var(--secondary);
}

.file-upload-area .file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-upload-content i {
    font-size: 2.5rem;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
    display: block;
}

.file-upload-content p {
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

.file-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary);
}

/* Import Preview */
.import-preview {
    background: var(--bg);
    border-radius: var(--border-radius);
    padding: var(--space-lg);
}

.preview-stats {
    display: flex;
    gap: var(--space-xl);
    margin-bottom: var(--space-lg);
}

.preview-stat {
    text-align: center;
}

.preview-stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.preview-stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.preview-details {
    border-top: 1px solid var(--border);
    padding-top: var(--space-lg);
}

.preview-details details {
    margin-bottom: var(--space-md);
}

.preview-details summary {
    cursor: pointer;
    font-weight: 500;
    padding: var(--space-sm) 0;
    color: var(--primary);
}

.preview-list {
    max-height: 200px;
    overflow-y: auto;
    padding: var(--space-md);
    background: var(--bg-white);
    border-radius: var(--border-radius);
    margin-top: var(--space-sm);
}

.preview-item {
    display: flex;
    justify-content: space-between;
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.preview-item:last-child {
    border-bottom: none;
}

.preview-item strong {
    font-weight: 500;
}

.preview-item span {
    color: var(--text-muted);
}

.preview-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: var(--space-md);
}

/* Import Status */
.import-status {
    padding: var(--space-md);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    margin-top: var(--space-lg);
}

.status-info {
    background: var(--info-bg);
    color: var(--info);
}

.status-success {
    background: var(--success-bg);
    color: var(--success);
}

.status-error {
    background: var(--error-bg);
    color: var(--error);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .admin-app {
        grid-template-columns: 1fr;
    }

    #sidebar-toggle {
        display: flex;
    }

    .admin-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform var(--transition);
        z-index: 99;
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    .admin-main {
        grid-column: 1;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }

    .search-box input {
        width: 100%;
    }

    .data-table {
        font-size: 0.8125rem;
    }

    .data-table th,
    .data-table td {
        padding: var(--space-sm);
    }
}
