/* ============================================
   CloudBill 365 — Design System
   Dashboard profesional dark mode
   ============================================ */

/* --- CSS Variables --- */
:root {
    /* Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --bg-sidebar: #0c1222;
    --bg-input: rgba(15, 23, 42, 0.8);

    --accent-blue: #38bdf8;
    --accent-violet: #a78bfa;
    --accent-green: #4ade80;
    --accent-orange: #fb923c;
    --accent-red: #f87171;
    --accent-cyan: #22d3ee;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border-color: rgba(148, 163, 184, 0.1);
    --border-hover: rgba(148, 163, 184, 0.2);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-glow-blue: 0 0 20px rgba(56, 189, 248, 0.15);
    --shadow-glow-green: 0 0 20px rgba(74, 222, 128, 0.15);
    --shadow-glow-red: 0 0 20px rgba(248, 113, 113, 0.15);
    --shadow-glow-violet: 0 0 20px rgba(167, 139, 250, 0.15);

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

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

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.logo-img {
    height: 34px;
    width: auto;
    flex-shrink: 0;
    filter: invert(1) hue-rotate(180deg) brightness(1.15);
}

.logo-app-name {
    font-size: 1.05rem;
    font-weight: 300;
    color: var(--text-secondary);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.logo-app-name strong {
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.93rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-item:hover {
    background: rgba(56, 189, 248, 0.08);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blue);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent-blue);
    border-radius: 0 3px 3px 0;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.demo-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(251, 146, 60, 0.1);
    border: 1px solid rgba(251, 146, 60, 0.2);
    border-radius: var(--radius-sm);
    color: var(--accent-orange);
    font-size: 0.8rem;
    font-weight: 500;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

/* --- Topbar --- */
.topbar {
    height: var(--topbar-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-orange);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============================================
   PAGES
   ============================================ */
.page {
    display: none;
    padding: 28px;
    animation: fadeIn var(--transition-normal) ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   KPI CARDS
   ============================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 18px;
    transition: all var(--transition-normal);
    cursor: default;
}

.kpi-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.kpi-card:nth-child(1):hover { box-shadow: var(--shadow-glow-blue); }
.kpi-card:nth-child(2):hover { box-shadow: var(--shadow-glow-red); }
.kpi-card:nth-child(3):hover { box-shadow: var(--shadow-glow-green); }
.kpi-card:nth-child(4):hover { box-shadow: var(--shadow-glow-violet); }

.kpi-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon.blue { background: rgba(56, 189, 248, 0.12); color: var(--accent-blue); }
.kpi-icon.red { background: rgba(248, 113, 113, 0.12); color: var(--accent-red); }
.kpi-icon.green { background: rgba(74, 222, 128, 0.12); color: var(--accent-green); }
.kpi-icon.violet { background: rgba(167, 139, 250, 0.12); color: var(--accent-violet); }

.kpi-data {
    display: flex;
    flex-direction: column;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ============================================
   CHARTS
   ============================================ */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.charts-grid.single {
    grid-template-columns: 1fr;
}

.chart-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 22px;
}

.chart-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.chart-container {
    position: relative;
    height: 280px;
}

.chart-container-tall {
    height: 480px;
}

/* ============================================
   ALERTS
   ============================================ */
.alerts-section {
    margin-bottom: 20px;
}

.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
}

.alert-warning {
    background: rgba(251, 146, 60, 0.1);
    border: 1px solid rgba(251, 146, 60, 0.2);
    color: var(--accent-orange);
}

.alert-danger {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.2);
    color: var(--accent-red);
}

/* ============================================
   PAGE HEADER
   ============================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    width: 360px;
    transition: border-color var(--transition-fast);
}

.search-box:focus-within {
    border-color: var(--accent-blue);
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    width: 100%;
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.3);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* ============================================
   DATA TABLES
   ============================================ */
.table-container {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

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

.data-table thead {
    background: rgba(15, 23, 42, 0.5);
}

.data-table th {
    padding: 12px 16px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-fast);
}

.data-table th:hover {
    color: var(--accent-blue);
}

.data-table td {
    padding: 12px 16px;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(56, 189, 248, 0.04);
}

.text-right {
    text-align: right;
}

.table-footer {
    padding: 12px 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-active { background: rgba(74, 222, 128, 0.12); color: var(--accent-green); }
.badge-suspended { background: rgba(251, 146, 60, 0.12); color: var(--accent-orange); }
.badge-canceled { background: rgba(248, 113, 113, 0.12); color: var(--accent-red); }
.badge-draft { background: rgba(148, 163, 184, 0.12); color: var(--text-secondary); }
.badge-open { background: rgba(56, 189, 248, 0.12); color: var(--accent-blue); }
.badge-closed { background: rgba(74, 222, 128, 0.12); color: var(--accent-green); }
.badge-past_due { background: rgba(248, 113, 113, 0.12); color: var(--accent-red); }

.badge-critical { background: rgba(248, 113, 113, 0.15); color: var(--accent-red); }
.badge-warning { background: rgba(251, 146, 60, 0.15); color: var(--accent-orange); }
.badge-ok { background: rgba(74, 222, 128, 0.15); color: var(--accent-green); }
.badge-expired { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

/* --- Price colors --- */
.text-pvd { color: var(--accent-red); }
.text-pvp { color: var(--accent-green); }
.text-margin { color: var(--accent-violet); }
.text-warning { color: var(--accent-orange); }
.text-critical { color: var(--accent-red); font-weight: 600; }

/* --- Margin percentage badge --- */
.margin-pct {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 4px;
    vertical-align: middle;
}

.text-margin-high {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
}

.text-margin-mid {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.text-margin-low {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

/* ============================================
   LICENSE GROUPS (Collapsible by customer)
   ============================================ */
#licenses-grouped {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.license-group {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition-normal);
}

.license-group:hover {
    border-color: var(--border-hover);
}

.license-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
    gap: 16px;
}

.license-group-header:hover {
    background: rgba(56, 189, 248, 0.04);
}

.license-group-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.license-group-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.license-group-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.license-group-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.license-group-kpis {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
}

.license-group-kpi {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 60px;
}

.license-group-kpi-val {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
}

.license-group-kpi-lbl {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.license-group-chevron {
    color: var(--text-muted);
    transition: transform var(--transition-normal);
    flex-shrink: 0;
}

.license-group.collapsed .license-group-chevron {
    transform: rotate(-90deg);
}

.license-group-body {
    border-top: 1px solid var(--border-color);
    max-height: 800px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease;
    opacity: 1;
}

.license-group.collapsed .license-group-body {
    max-height: 0;
    border-top-color: transparent;
    opacity: 0;
}

.license-group-body .data-table {
    border-radius: 0;
}

.license-group-body .data-table thead {
    background: rgba(15, 23, 42, 0.4);
}

.license-group-body .data-table th {
    font-size: 0.72rem;
    padding: 8px 16px;
}

.license-group-body .data-table td {
    padding: 10px 16px;
    font-size: 0.85rem;
}

/* ============================================
   CONTRACTS URGENCY PANEL
   ============================================ */
.contracts-urgency {
    margin-bottom: 20px;
}

.urgency-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(251, 146, 60, 0.08);
    border: 1px solid rgba(251, 146, 60, 0.2);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-orange);
}

.urgency-legend {
    display: flex;
    gap: 16px;
    margin-left: auto;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.urgency-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.urgency-legend-item .badge {
    font-size: 0.65rem;
    padding: 1px 6px;
}

.urgency-empty {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: rgba(52, 211, 153, 0.06);
    border: 1px solid rgba(52, 211, 153, 0.15);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--accent-green);
}

/* --- Contract Filters --- */
.contracts-filter-bar {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 3px;
}

.contracts-filter-btn {
    padding: 6px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.contracts-filter-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.contracts-filter-btn.active {
    background: var(--accent-blue);
    color: white;
}

.urgency-cards {
    display: flex;
    gap: 12px;
    padding: 16px;
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.urgency-card {
    flex: 0 0 220px;
    padding: 14px 16px;
    background: rgba(15, 23, 42, 0.5);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-orange);
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.urgency-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.urgency-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.urgency-card-days {
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1;
}

.urgency-card-days.critical { color: var(--accent-red); }
.urgency-card-days.warning { color: var(--accent-orange); }

.urgency-card-product {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.urgency-card-customer {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.urgency-card-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    padding-top: 6px;
    margin-top: 2px;
}

#contracts-grouped {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================
   CUSTOMERS GRID
   ============================================ */
.customers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 18px;
}

.customer-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 22px;
    transition: all var(--transition-normal);
}

.customer-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.customer-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.customer-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.customer-card-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.customer-card-email {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.customer-card-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

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

.customer-stat-value {
    font-weight: 700;
    font-size: 1.1rem;
    display: block;
}

.customer-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ============================================
   SETTINGS
   ============================================ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.settings-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
}

.settings-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.settings-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    transition: border-color var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: var(--accent-blue);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.settings-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.connection-result {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
    font-size: 0.9rem;
}

.connection-result.success {
    border-color: rgba(74, 222, 128, 0.3);
    color: var(--accent-green);
}

.connection-result.error {
    border-color: rgba(248, 113, 113, 0.3);
    color: var(--accent-red);
}

/* Settings — Info Banner */
.settings-info-banner {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    background: rgba(96, 165, 250, 0.08);
    border: 1px solid rgba(96, 165, 250, 0.2);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 24px;
}

.settings-azure-warning {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    background: rgba(239, 68, 68, 0.08);
    border: 2px solid rgba(239, 68, 68, 0.4);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    margin-bottom: 24px;
}

.azure-warning-icon {
    color: var(--accent-red);
    flex-shrink: 0;
    margin-top: 2px;
}

.azure-warning-content {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.azure-warning-content strong:first-child {
    color: var(--accent-red);
    display: block;
    margin-bottom: 6px;
    font-size: 1rem;
}

.azure-warning-content p {
    margin: 4px 0;
}

.info-banner-icon {
    color: var(--accent-blue);
    flex-shrink: 0;
    margin-top: 2px;
}

.info-banner-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.info-banner-content strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.info-banner-content p {
    margin: 0;
}

/* Settings — Warning box */
.settings-warning {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.25);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.settings-warning svg {
    color: var(--accent-orange);
    flex-shrink: 0;
    margin-top: 1px;
}

/* Settings — How-to instructions */
.settings-how-to {
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 18px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.settings-how-to strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 8px;
    font-size: 0.82rem;
}

.settings-how-to ol {
    margin: 0;
    padding-left: 18px;
}

.settings-how-to li {
    margin-bottom: 4px;
}

.settings-how-to a {
    color: var(--accent-blue);
    text-decoration: none;
}

.settings-how-to a:hover {
    text-decoration: underline;
}

.settings-how-to code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
}

/* Settings — Footer note */
.settings-info-footer {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 20px;
    padding: 14px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    border-top: 1px solid var(--border-color);
}

.settings-info-footer svg {
    flex-shrink: 0;
    color: var(--accent-green);
    margin-top: 1px;
}

/* ============================================
   TOGGLE SWITCH
   ============================================ */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toggle-input {
    display: none;
}

.toggle-switch {
    width: 40px;
    height: 22px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 11px;
    position: relative;
    transition: all var(--transition-fast);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle-input:checked + .toggle-switch {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent-blue);
}

.toggle-input:checked + .toggle-switch::after {
    left: 20px;
    background: var(--accent-blue);
}

/* ============================================
   LOADING SKELETON
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(148,163,184,0.08) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   CUSTOMER CARD — CLICKABLE
   ============================================ */
.customer-card.clickable {
    cursor: pointer;
}

.customer-card.clickable:hover {
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-glow-blue);
}

/* --- Clickable table rows --- */
.clickable-row {
    cursor: pointer;
}

.clickable-row:hover {
    background: rgba(56, 189, 248, 0.08) !important;
}

.text-muted-cell {
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* ============================================
   CUSTOMER DETAIL MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: modal-fade-in 200ms ease;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 1100px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    animation: modal-slide-up 300ms ease;
}

@keyframes modal-slide-up {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-avatar {
    width: 52px;
    height: 52px;
    font-size: 1.3rem;
}

.modal-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.modal-close {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(248, 113, 113, 0.15);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.modal-kpis {
    display: flex;
    gap: 0;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.3);
}

.modal-kpi {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    position: relative;
}

.modal-kpi:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: var(--border-color);
}

.modal-kpi-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.3;
}

.modal-kpi-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
    display: block;
}

.modal-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 28px 12px;
}

.modal-section-header .modal-section-title {
    padding: 0;
}

.modal-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 18px 28px 12px;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.78rem;
    gap: 6px;
}

/* Sortable table headers */
.sortable {
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-fast);
}

.sortable:hover {
    color: var(--accent-blue);
}

.sortable.sorted {
    color: var(--accent-blue);
}

.sort-icon {
    font-size: 0.7rem;
    opacity: 0.4;
    margin-left: 2px;
}

.sortable.sorted .sort-icon {
    opacity: 1;
    color: var(--accent-blue);
}

.modal-table {
    border: none;
    border-radius: 0;
    margin: 0;
    background: transparent;
}

.modal-table .data-table td {
    white-space: normal;
    word-break: break-word;
}

.modal-table .data-table td:first-child {
    max-width: 260px;
}

/* Extra badge for deleted status */
.badge-deleted {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-muted);
}

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

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .search-box {
        width: 100%;
    }
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    .page {
        padding: 16px;
    }
    .topbar {
        padding: 0 16px;
    }

    .modal-content {
        max-height: 95vh;
    }
    .modal-overlay {
        padding: 8px;
    }
    .modal-kpis {
        flex-wrap: wrap;
    }
    .modal-kpi {
        min-width: 33%;
    }
}

/* === Invoice Proration & Grouped View === */

.inv-proration-banner {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(251, 146, 60, 0.08);
    border: 1px solid rgba(251, 146, 60, 0.25);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin: 0 28px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.inv-proration-banner svg {
    color: var(--accent-orange);
    flex-shrink: 0;
    margin-top: 2px;
}

.badge-proration {
    background: rgba(251, 146, 60, 0.15);
    color: var(--accent-orange);
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 4px;
}

.row-prorated {
    background: rgba(251, 146, 60, 0.03);
}

.inv-view-toggle {
    display: flex;
    gap: 2px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.inv-view-btn {
    padding: 5px 14px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.inv-view-btn:hover {
    color: var(--text-primary);
}

.inv-view-btn.active {
    background: var(--accent-blue);
    color: white;
}

.inv-customer-group {
    margin: 0 28px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.inv-customer-lines {
    display: none;
    border-top: 1px solid var(--border-color);
}

.inv-customer-group.expanded .inv-customer-lines {
    display: block;
}

.inv-chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.inv-customer-group.expanded .inv-chevron {
    transform: rotate(180deg);
}

.inv-customer-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 8px;
}

.inv-customer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    cursor: pointer;
    transition: background 0.2s;
}

.inv-customer-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.inv-customer-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.inv-customer-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.inv-customer-total {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-green);
}

.inv-customer-body {
    border-top: 1px solid var(--border-color);
}

.inv-customer-body .data-table {
    margin: 0;
    border-radius: 0;
}

.inv-subtotal-row {
    background: rgba(96, 165, 250, 0.06);
    border-top: 1px solid var(--border-color);
}

.inv-subtotal-row td {
    padding: 10px 14px;
    font-size: 0.85rem;
}

.badge-azure { background: rgba(34, 211, 238, 0.12); color: var(--accent-cyan); font-size: 0.6rem; }
.badge-m365 { background: rgba(96, 165, 250, 0.12); color: var(--accent-blue); font-size: 0.6rem; }

.inv-category-section {
    padding: 0;
}

.inv-category-label {
    padding: 12px 18px 4px;
    font-weight: 600;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.inv-category-section .data-table {
    margin: 0;
    border-radius: 0;
}

.inv-category-section + .inv-category-section {
    border-top: 1px solid var(--border-color);
}

.inv-grand-total-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 18px;
    background: rgba(96, 165, 250, 0.08);
    border-top: 2px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--accent-green);
}

/* Tab summary KPIs */
.inv-tab-kpis {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.inv-tab-kpi {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inv-tab-kpi-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.inv-tab-kpi-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Invoice customer search */
.inv-search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 12px;
    transition: border-color 0.2s;
}

.inv-search-box:focus-within {
    border-color: var(--accent-blue);
}

.inv-search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.inv-search-box input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
}

.inv-search-box input::placeholder {
    color: var(--text-muted);
}

/* Ensure SVG inside buttons don't steal click events */
.inv-view-btn svg,
.inv-view-btn span {
    pointer-events: none;
}

/* Spinner for loading states */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Azure Consumption Section
   ============================================ */
.azure-period-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 8px;
    color: var(--accent-blue);
    font-size: 0.9rem;
    font-weight: 500;
}
