/* C-N Double Links Invoice System - Main Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #1a478a;
    --primary-dark: #0f2d5e;
    --primary-light: #2a5fa8;
    --accent: #10b981;
    --accent-dark: #059669;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f0f2f5;
    --card: #ffffff;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    height: 100vh;
    max-height: 100vh;
    position: fixed;
    left: 0; top: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
}

.sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-logo h1 {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.sidebar-logo span {
    font-size: 12px;
    color: #94a3b8;
    display: block;
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: 16px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,0.45) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(148,163,184,0.35);
    border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(148,163,184,0.6);
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.nav-item .icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}

.sidebar-user .info {
    flex: 1;
}

.sidebar-user .info .name {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.sidebar-user .info .role {
    color: #64748b;
    font-size: 11px;
}

.sidebar-user .logout-btn {
    color: #64748b;
    text-decoration: none;
    font-size: 18px;
    transition: var(--transition);
}

.sidebar-user .logout-btn:hover { color: var(--danger); }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: 260px;
    flex: 1;
    min-height: 100vh;
}

.page-header {
    background: var(--card);
    padding: 24px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.page-header .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.page-body {
    padding: 24px 32px;
}

/* ===== CARDS ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body { padding: 20px; }

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.blue { background: rgba(26,71,138,0.1); color: var(--primary); }
.stat-icon.green { background: rgba(16,185,129,0.1); color: var(--accent); }
.stat-icon.orange { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-icon.purple { background: rgba(139,92,246,0.1); color: #8b5cf6; }

.stat-info .label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-info .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-success {
    background: var(--accent);
    color: #fff;
}
.btn-success:hover { background: var(--accent-dark); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #dc2626; }

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--text-secondary); }

.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ===== TABLE ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
}

.data-table tbody td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-voided { background: #fee2e2; color: #991b1b; }
.badge-credit { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    background: #fff;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,71,138,0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.password-admin-layout {
    display: grid;
    grid-template-columns: minmax(320px, 520px) 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1100px) {
    .password-admin-layout {
        grid-template-columns: 1fr;
    }
}

/* ===== INVOICE FORM SPECIFIC ===== */
.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.invoice-items-table thead th {
    padding: 10px 12px;
    background: var(--sidebar-bg);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.invoice-items-table thead th:first-child { text-align: left; border-radius: 8px 0 0 0; }
.invoice-items-table thead th:last-child { border-radius: 0 8px 0 0; }

.invoice-items-table tbody td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.invoice-items-table .form-control {
    padding: 8px 10px;
    font-size: 13px;
}

.invoice-items-table .remove-row {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 20px;
    border-radius: 50%;
    transition: var(--transition);
}

.invoice-items-table .remove-row:hover {
    background: #fee2e2;
}

.totals-section {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.totals-box {
    min-width: 300px;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.totals-row.total {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding: 12px 0;
}

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, #2a5fa8 100%);
}

.login-card {
    background: var(--card);
    border-radius: 16px;
    padding: 48px 40px;
    width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    color: var(--primary);
}

.login-card .company-chinese {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-card .form-control {
    padding: 14px 16px;
    font-size: 15px;
}

.login-card .btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    justify-content: center;
}

/* ===== FLASH MESSAGES ===== */
.flash-messages {
    padding: 0 32px;
    margin-top: 16px;
}

.alert {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--card);
    border-radius: var(--radius);
    width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar { width: 0; overflow: hidden; }
    .main-content { margin-left: 0; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; }
