/* ── Customer Portal — Light Theme ── */

:root {
    --bg-page: #F5F5F7;
    --bg-sidebar: #FAFAFA;
    --bg-card: #FFFFFF;
    --border: #E8E8E8;
    --border-light: #F0F0F0;
    --text-primary: #0D0D0D;
    --text-secondary: #7A7A7A;
    --text-muted: #A0A0A0;
    --accent: #2563EB;
    --accent-bg: #EFF6FF;
    --success: #22C55E;
    --success-bg: #F0FDF4;
    --warning: #F97316;
    --warning-bg: #FFF7ED;
    --error: #EF4444;
    --error-bg: #FEF2F2;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

body {
    font-family: var(--font);
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ── Layout ── */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 32px 16px 24px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
}

.sidebar-top {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 8px;
}

.logo-mark {
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-mark img {
    width: 96px;
    height: 96px;
    object-fit: contain;
}

.logo-mark svg {
    width: 18px;
    height: 18px;
    color: white;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    transition: all 0.15s ease;
    cursor: pointer;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--border-light);
    color: var(--text-primary);
    text-decoration: none;
}

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

.nav-item.active:hover {
    background: #1d4ed8;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Sidebar bottom */

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 8px 0;
    border-top: 1px solid var(--border);
}

.avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Main Content ── */

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.page-header .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text-secondary);
}

.icon-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Cards ── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-header a {
    font-size: 13px;
    font-weight: 500;
}

/* ── Content Grid ── */

.content-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    flex: 1;
}

/* ── Activity List ── */

.activity-list {
    list-style: none;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s ease;
}

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

.activity-item:hover {
    background: #FAFAFA;
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}

.activity-dot.success {
    background: var(--success);
}

.activity-dot.info {
    background: var(--accent);
}

.activity-dot.warning {
    background: var(--warning);
}

.activity-dot.error {
    background: var(--error);
}

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-action {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.activity-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.activity-empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ── Service Items ── */

.service-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-light);
}

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

.service-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.service-icon svg {
    width: 20px;
    height: 20px;
}

.service-info {
    flex: 1;
    min-width: 0;
}

.service-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.service-status {
    font-size: 12px;
    margin-top: 2px;
}

.service-status.connected {
    color: var(--success);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-xs);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    text-decoration: none;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

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

.btn-outline:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.connected-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--success);
    font-weight: 500;
}

.connected-badge svg {
    width: 14px;
    height: 14px;
}

/* ── Login Page ── */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-page);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-card .logo {
    justify-content: center;
    margin-bottom: 32px;
    gap: 6px;
}

.login-card .logo-mark {
    width: 64px;
    height: 64px;
}

.login-card .logo-mark img {
    width: 64px;
    height: 64px;
}

.login-card h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-card .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.form-group {
    text-align: left;
    margin-bottom: 20px;
}

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

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

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.btn-full {
    width: 100%;
    padding: 12px;
    font-size: 14px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 20px;
    text-align: left;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #FECACA;
}

.alert-success {
    background: var(--success-bg);
    color: #16a34a;
    border: 1px solid #BBF7D0;
}

/* ── Settings ── */

.settings-section {
    padding: 24px;
}

.settings-section+.settings-section {
    border-top: 1px solid var(--border-light);
}

.settings-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.settings-section p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.settings-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.settings-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.logout-link {
    color: var(--error);
    font-size: 13px;
    font-weight: 500;
}

.logout-link:hover {
    text-decoration: underline;
}

/* ── dev link (only in dev mode) ── */

.dev-link {
    margin-top: 16px;
    padding: 12px;
    background: var(--warning-bg);
    border: 1px solid #FED7AA;
    border-radius: var(--radius-sm);
    font-size: 12px;
    word-break: break-all;
    text-align: left;
}

.dev-link strong {
    display: block;
    margin-bottom: 4px;
    color: var(--warning);
}

/* ── Responsive ── */

/* Bottom Tab Bar — hidden on desktop, shown on mobile */
.mobile-tab-bar {
    display: none;
}

@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Hide sidebar completely on mobile */
    .sidebar {
        display: none;
    }

    /* Full width content */
    .main-content {
        margin-left: 0;
        padding: 20px 16px 90px; /* bottom padding for tab bar */
    }

    .page-header h1 {
        font-size: 20px;
    }

    .page-header .subtitle {
        font-size: 13px;
    }

    /* Cards — tighter on mobile */
    .card {
        padding: 16px;
        border-radius: 12px;
    }

    .card-header {
        padding-bottom: 12px;
    }

    .card-header h2 {
        font-size: 15px;
    }

    /* Activity items — more compact */
    .activity-item {
        padding: 10px 0;
    }

    .activity-action {
        font-size: 13px;
    }

    .activity-meta {
        font-size: 11px;
    }

    /* Tables — scroll horizontally */
    .card table,
    .expenses-table,
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 13px;
    }

    /* Form inputs — larger touch targets */
    .form-input,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* prevents iOS zoom on focus */
        padding: 12px !important;
        min-height: 44px;
    }

    /* Buttons — larger touch targets */
    .btn,
    .btn-primary,
    .btn-save,
    button[type="submit"] {
        min-height: 44px;
        font-size: 14px;
        padding: 10px 20px;
    }

    /* Upload zone — taller for easier tapping */
    .upload-zone {
        min-height: 120px;
        padding: 24px 16px;
    }

    /* Header actions */
    .header-actions {
        gap: 8px;
    }

    .icon-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Show bottom tab bar */
    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: #fff;
        border-top: 1px solid var(--border);
        padding: 6px 0 env(safe-area-inset-bottom, 6px);
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    }

    .tab-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        text-decoration: none;
        color: var(--text-secondary);
        font-size: 10px;
        font-weight: 500;
        padding: 4px 8px;
        border-radius: 8px;
        transition: all 0.15s ease;
        min-width: 56px;
    }

    .tab-item svg {
        width: 22px;
        height: 22px;
    }

    .tab-item.active {
        color: var(--accent);
    }

    .tab-item.active svg {
        stroke-width: 2.5;
    }

    /* Service items — stack better */
    .service-item {
        padding: 12px 0;
    }

    /* Connected badge */
    .connected-badge {
        font-size: 11px;
        padding: 4px 8px;
    }

    /* Expense rows */
    .expense-row td {
        padding: 10px 8px;
    }

    /* Form rows — stack on mobile */
    .form-row {
        flex-direction: column;
        gap: 12px;
    }

    .form-group {
        width: 100%;
    }
}

/* ── Uploads Page ── */

.upload-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 24px;
}

.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 24px;
    padding: 48px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent);
}

.upload-zone svg {
    opacity: 0.5;
}

.upload-zone:hover svg,
.upload-zone.drag-over svg {
    opacity: 1;
}

.upload-zone-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.upload-browse {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
}

.upload-browse:hover {
    text-decoration: underline;
}

.upload-zone-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.upload-file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 24px;
    padding: 12px 16px;
    background: var(--accent-bg);
    border: 1px solid #BFDBFE;
    border-radius: var(--radius-sm);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.file-info svg {
    color: var(--accent);
    flex-shrink: 0;
}

.file-size {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 13px;
}

.file-remove {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.file-remove:hover {
    color: var(--error);
}

.upload-actions {
    padding: 0 24px;
}

.upload-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

#uploadResult {
    padding: 0 24px;
}

/* Upload file list */

.uploads-list {
    list-style: none;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s ease;
}

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

.upload-item:hover {
    background: #FAFAFA;
}

.upload-item-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.upload-item-icon.pdf {
    background: var(--error-bg);
    color: var(--error);
}

.upload-item-icon.image {
    background: var(--success-bg);
    color: var(--success);
}

.upload-item-icon.other {
    background: var(--accent-bg);
    color: var(--accent);
}

.upload-item-info {
    flex: 1;
    min-width: 0;
}

.upload-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Modal Overlay ── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    max-width: 600px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 1.5rem;
}

.modal-content-lg {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.modal-header h2,
.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.5rem;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}