/* ReceiptWave Business Portal — Dashboard Styles */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

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

:root {
    --teal: #2EBFA5;
    --teal-dark: #259688;
    --navy: #1B2A4A;
    --navy-light: #1e293b;
    --bg: #F8FAFC;
    --white: #ffffff;
    --text: #1E293B;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #22c55e;
    --info: #3b82f6;
    --topbar-height: 56px;
    --rw-navy: #1B2A4A;
    --rw-teal: #2EBFA5;
    --rw-nav-height: 56px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === TOP NAVIGATION === */
.portal-topnav {
    height: var(--rw-nav-height);
    background: var(--rw-navy);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Logo */
.nav-logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    border-right: 1px solid rgba(255,255,255,0.12);
    padding-right: 20px;
    margin-right: 4px;
    text-decoration: none;
    flex-shrink: 0;
}
.nav-logo-badge { width: 28px; height: 28px; flex-shrink: 0; }
.nav-wordmark { font-family: 'Sora', sans-serif; font-size: 15px; font-weight: 700; color: white; letter-spacing: -0.2px; white-space: nowrap; }
.nav-wordmark-receipt { color: white; }
.nav-wordmark-wave { color: var(--rw-teal); }

/* Nav items */
.nav-items {
    display: flex;
    align-items: stretch;
    flex: 1;
    height: 100%;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    font-size: 13px;
    color: rgba(255,255,255,0.65);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    text-decoration: none;
    transition: color 0.15s;
    height: 100%;
}
.nav-item:hover { color: white; background: rgba(255,255,255,0.06); }
.nav-item--active { color: white; border-bottom-color: var(--rw-teal); }
.nav-item--has-dropdown::after {
    content: '';
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    margin-left: 4px;
}

/* Dropdowns */
.nav-item--has-dropdown {
    position: relative;
}
.nav-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    padding: 6px 0;
    display: none;
    z-index: 200;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
.nav-item--has-dropdown.open .nav-dropdown { display: block; }
.nav-dropdown-item {
    display: block;
    padding: 8px 14px;
    font-size: 13px;
    color: #1B2A4A;
    text-decoration: none;
    white-space: nowrap;
}
.nav-dropdown-item:hover { background: #f3f4f6; }
.nav-dropdown-item--active { color: var(--rw-teal); font-weight: 500; }
.nav-dropdown-divider { height: 1px; background: #E2E8F0; margin: 6px 0; }
.nav-dropdown-label { padding: 6px 14px 2px; font-size: 10px; font-weight: 600; color: #94A3B8; text-transform: uppercase; letter-spacing: 0.5px; }

/* User area */
.nav-user-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    padding-left: 16px;
    border-left: 1px solid rgba(255,255,255,0.12);
    flex-shrink: 0;
}
.nav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--rw-teal);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: white;
}
.nav-username { font-size: 13px; color: rgba(255,255,255,0.8); white-space: nowrap; }
.nav-signout {
    font-size: 12px;
    color: rgba(255,255,255,0.45);
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
    background: none;
    font-family: inherit;
}
.nav-signout:hover {
    color: rgba(255,255,255,0.8);
    border-color: rgba(255,255,255,0.35);
}

/* === MAIN CONTENT === */
.portal-main {
    margin-left: 0;
    padding-top: var(--rw-nav-height);
    min-height: 100vh;
}

.portal-content { padding: 24px; max-width: 1280px; margin: 0 auto; }

/* === PAGE HEADER === */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.page-header p { font-size: 0.9rem; color: var(--text-secondary); margin-top: 4px; }

/* === STAT CARDS === */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.stat-card .stat-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 8px;
}

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

.stat-card .stat-value.money::before { content: "$"; }

/* === CARDS === */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--navy);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 20px; }

/* === TABLES === */
.portal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.portal-table thead th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--white);
}

.portal-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.portal-table tbody tr:nth-child(even) { background: #f9fafb; }
.portal-table tbody tr:hover { background: #f0fdf4; }

.portal-table tbody td { padding: 10px 12px; }

.portal-table a.row-link {
    color: var(--navy);
    text-decoration: none;
    font-weight: 500;
}

.portal-table a.row-link:hover { color: var(--teal); }

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }
.badge-ready { background: #ccfbf1; color: #0d9488; }
.badge-tapped { background: #dbeafe; color: #1e40af; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--navy);
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    transition: border-color 0.15s;
}

.form-control:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(46,191,165,0.15); }
.form-control[readonly] { background: #f8fafc; color: var(--text-secondary); }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
    min-height: 44px;
}

.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-link { background: none; color: var(--teal); padding: 0; }
.btn-link:hover { text-decoration: underline; }

/* === FILTER BAR === */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: #fafafa;
    border-radius: 10px 10px 0 0;
}

.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { width: 160px; padding: 7px 10px; font-size: 0.85rem; }

/* === PAGINATION === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    font-size: 0.875rem;
}

.pagination a, .pagination span {
    padding: 6px 14px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
}

.pagination a:hover { background: #e2e8f0; }
.pagination .disabled { color: #cbd5e1; pointer-events: none; }
.pagination .current { font-weight: 600; color: var(--navy); }

/* === EMPTY STATE === */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1.1rem; color: var(--navy); margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; max-width: 400px; margin: 0 auto; }

/* === ALERTS === */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* === KEY DISPLAY === */
.key-display {
    background: #fef3c7;
    border: 2px solid #fbbf24;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.key-display .key-value {
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    padding: 8px 12px;
    background: #fff;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    width: 100%;
}

/* === DEVICE CARDS === */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--white);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.device-card .setup-code {
    font-family: 'Inter', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 0.05em;
}

.device-card .device-info { margin-top: 12px; font-size: 0.85rem; color: var(--text-secondary); }
.device-card .device-info dt { font-weight: 600; color: var(--text); }
.device-card .device-info dd { margin-bottom: 8px; }
.device-warning { color: var(--danger); font-size: 0.8rem; font-weight: 500; margin-top: 8px; }

/* === DETAIL PAGE === */
.detail-header { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-bottom: 12px; }
.back-link { color: var(--teal); text-decoration: none; font-size: 0.875rem; font-weight: 500; }
.back-link:hover { text-decoration: underline; }

.receipt-raw {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    color: var(--navy);
    padding: 12px 0;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .nav-username { display: none; }
    .nav-logo-area { padding-right: 12px; margin-right: 0; }
    .nav-wordmark { display: none; }
    .nav-item { padding: 0 10px; font-size: 12px; }
    .nav-user-area { gap: 8px; padding-left: 8px; }
    .portal-content { padding: 16px; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-control { width: 100%; }
    .device-grid { grid-template-columns: 1fr; }
}

/* === FORM INPUT (alias) === */
.form-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    transition: border-color 0.15s;
}

.form-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(46,191,165,0.15); }
.form-input:disabled { background: #f8fafc; color: var(--text-secondary); cursor: not-allowed; }

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--navy);
    margin-bottom: 4px;
}

/* === DEVICE INFO ROWS === */
.device-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.875rem;
}

.device-label {
    font-weight: 600;
    color: var(--text);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.text-secondary { color: var(--text-secondary); }

/* === SETUP CODE (standalone) === */
.setup-code {
    font-family: 'Inter', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 0.05em;
}

/* === PRIMARY COLOR VAR === */
:root { --primary: var(--teal); }

/* === BAR CHART (analytics) === */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 8px 0; }
.bar-chart .bar { background: var(--teal); border-radius: 3px 3px 0 0; min-width: 20px; flex: 1; transition: height 0.3s; }
.bar-chart .bar:hover { background: var(--teal-dark); }

/* === HORIZONTAL BAR === */
.hbar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.hbar-label { width: 80px; font-size: 0.8rem; text-align: right; color: var(--text-secondary); }
.hbar-track { flex: 1; height: 24px; background: var(--border); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--teal); border-radius: 4px; display: flex; align-items: center; padding-left: 8px; font-size: 0.75rem; color: #fff; font-weight: 600; }

/* === ESG METRICS === */
.esg-metric { text-align: center; padding: 20px; }
.esg-value { font-size: 2rem; font-weight: 700; color: var(--navy); }
.esg-unit { font-size: 0.85rem; color: var(--text-secondary); }
.esg-equivalent { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; background: #f0fdf4; margin-bottom: 8px; }
.esg-equivalent .emoji { font-size: 1.5rem; }
.esg-equivalent .value { font-weight: 700; color: var(--navy); }

/* === PLAN CARDS (billing) === */
.plan-card { border: 2px solid var(--border); border-radius: 16px; padding: 24px; text-align: center; }
.plan-card.current { border-color: var(--teal); }
.plan-price { font-size: 2rem; font-weight: 700; color: var(--navy); }
.plan-price .period { font-size: 0.85rem; font-weight: 400; color: var(--text-secondary); }
.plan-features { list-style: none; padding: 0; margin: 16px 0; text-align: left; }
.plan-features li { padding: 6px 0; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.plan-features li::before { content: "\2713  "; color: var(--teal); font-weight: 700; }

/* === USAGE BAR (billing) === */
.usage-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.usage-fill { height: 100%; background: var(--teal); border-radius: 4px; }
.usage-fill.warning { background: var(--warning); }
.usage-fill.danger { background: var(--danger); }

/* === PERIOD SELECTOR === */
.period-selector { display: flex; gap: 8px; margin-bottom: 16px; }
.period-btn { padding: 6px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--white); color: var(--text); text-decoration: none; font-size: 0.85rem; font-weight: 500; }
.period-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.period-btn:hover { border-color: var(--teal); }

/* === PRESET BUTTONS (export) === */
.preset-buttons { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.preset-btn { padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--white); color: var(--text); cursor: pointer; font-size: 0.8rem; font-family: inherit; }
.preset-btn:hover { border-color: var(--teal); color: var(--teal); }

/* === POS TILE GRID (login) === */
.pos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.pos-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.pos-tile.active { border-color: #006AFF; cursor: pointer; }
.pos-tile.active:hover { box-shadow: 0 2px 8px rgba(0, 106, 255, 0.15); }
.pos-tile.disabled { opacity: 0.5; cursor: default; }
.pos-tile .tile-info { display: flex; flex-direction: column; }
.pos-tile .coming-soon {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.pos-tile img, .pos-tile svg { width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0; }
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
}
.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.auth-divider span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === PROFILE HEADER === */
.profile-header {
    background: linear-gradient(135deg, #1B2A4A, #243660);
    border-radius: 12px;
    padding: 24px;
    color: #fff;
    margin-bottom: 24px;
}
.profile-header-inner { display: flex; align-items: center; gap: 16px; }
.profile-header .logo-circle {
    width: 56px; height: 56px; border-radius: 28px;
    background: var(--teal);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.profile-header .logo-circle img { width: 56px; height: 56px; border-radius: 28px; object-fit: cover; }
.profile-header .profile-info h2 { font-size: 1.3rem; margin-bottom: 4px; }
.profile-header .profile-info .meta { font-size: 0.85rem; color: rgba(255,255,255,0.7); }
.profile-header .profile-info .meta .badge { margin-left: 6px; }
.completeness-bar { height: 6px; background: rgba(255,255,255,0.2); border-radius: 3px; margin-top: 12px; }
.completeness-fill { height: 100%; background: var(--teal); border-radius: 3px; }
.completeness-text { font-size: 0.75rem; color: rgba(255,255,255,0.5); margin-top: 4px; }

/* === PROFILE SECTIONS === */
.profile-section { margin-bottom: 16px; }
.profile-section summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    font-weight: 600;
    color: var(--navy);
    list-style: none;
}
.profile-section summary::-webkit-details-marker { display: none; }
.profile-section .section-icon {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.profile-section .section-title-wrap { flex: 1; }
.profile-section .section-title { font-size: 0.95rem; }
.profile-section .section-subtitle { font-size: 0.8rem; color: var(--text-secondary); font-weight: 400; }
.profile-section .section-body { padding: 0 20px 20px; }
.source-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(46,191,165,0.12);
    color: var(--teal);
    margin-left: 6px;
}
.descriptor-display {
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.confidence-dot {
    display: inline-block;
    width: 8px; height: 8px; border-radius: 4px; margin-right: 6px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .form-row { grid-template-columns: 1fr; } }

/* Nav badge (message count) */
.nav-badge {
    background: var(--rw-teal);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}
