/* ═══════════════════════════════════════════════════════════════════════════
   RapidWeb Studio — App Styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
    --navy: #1a1f36;
    --navy-light: #252b48;
    --navy-hover: #2d3556;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --sidebar-w: 240px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.625rem 0.75rem; }
img { max-width: 100%; }

/* ── App Shell Layout ──────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--navy);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar__brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    letter-spacing: -0.02em;
}

.sidebar__nav {
    flex: 1;
    padding: 0.75rem 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
}

.nav-link:hover {
    background: var(--navy-hover);
    color: #e2e8f0;
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent);
    color: #fff;
}

.nav-link__icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar__footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar__user {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.sidebar__logout {
    font-size: 0.85rem;
    color: #94a3b8;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.sidebar__logout:hover {
    color: var(--danger);
}

/* ── Main Content ──────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 2rem;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* ── Cards / Stats ─────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card__label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

.stat-card__value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.stat-card__sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    font-size: 0.875rem;
}

table.data-table thead th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
}

table.data-table tbody td {
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.data-table tbody tr:hover {
    background: #f8fafc;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge--active { background: var(--success-light); color: #065f46; }
.badge--completed { background: var(--accent-light); color: #1e40af; }
.badge--draft { background: var(--warning-light); color: #92400e; }
.badge--invoiced { background: #e0e7ff; color: #3730a3; }
.badge--on_hold { background: #f1f5f9; color: #475569; }
.badge--quoted { background: #fce7f3; color: #9d174d; }
.badge--written_off { background: #f1f5f9; color: #64748b; }
.badge--billable { background: var(--success-light); color: #065f46; }
.badge--non-billable { background: #f1f5f9; color: #64748b; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

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

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

.btn--success {
    background: var(--success);
    color: #fff;
}

.btn--success:hover:not(:disabled) {
    background: #059669;
}

.btn--danger {
    background: var(--danger);
    color: #fff;
}

.btn--danger:hover:not(:disabled) {
    background: #dc2626;
}

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

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

.btn--sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}

.btn--full {
    width: 100%;
    justify-content: center;
}

.btn--icon {
    padding: 0.375rem;
    border-radius: var(--radius-sm);
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label,
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

input::placeholder {
    color: var(--text-light);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row > * {
    flex: 1;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

.form-check label {
    margin-bottom: 0;
    text-transform: none;
    font-weight: 500;
    color: var(--text);
    font-size: 0.9rem;
}

.form-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* ── Timer Widget ──────────────────────────────────────────────────────────── */
.timer-bar {
    background: var(--navy);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.timer-bar--idle {
    background: var(--surface);
    color: var(--text);
    border: 2px dashed var(--border);
    box-shadow: none;
}

.timer-bar__info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.timer-bar__pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 1.5s infinite;
    flex-shrink: 0;
}

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

.timer-bar__details {
    min-width: 0;
}

.timer-bar__job {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timer-bar__desc {
    font-size: 0.8rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timer-bar__time {
    font-size: 1.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    font-family: 'SF Mono', 'Consolas', monospace;
    flex-shrink: 0;
}

.timer-bar__actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Timer idle — inline form */
.timer-idle-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    width: 100%;
}

.timer-idle-form select,
.timer-idle-form input {
    flex: 1;
    min-width: 140px;
    padding: 0.5rem 0.75rem;
}

/* ── Login Page ────────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--navy);
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--navy);
    text-align: center;
    margin-bottom: 0.25rem;
}

.login-card__subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.login-card__toggle {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.login-card__toggle a {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
}

/* ── Toast Notifications ───────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    transform: translateX(120%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-md);
    max-width: 360px;
}

.toast--visible {
    transform: translateX(0);
}

.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--info { background: var(--accent); }

/* ── Loading / Empty States ────────────────────────────────────────────────── */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state__icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.empty-state__text {
    font-size: 0.95rem;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 1rem;
}

.modal-overlay--visible {
    opacity: 1;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 540px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay--visible .modal {
    transform: scale(1);
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.modal__header h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

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

.modal__close:hover {
    color: var(--text);
}

.modal__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ── Toolbar / Filters ─────────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar select,
.toolbar input {
    width: auto;
    min-width: 120px;
    padding: 0.375rem 0.625rem;
    font-size: 0.8rem;
}

/* ── Responsive — Mobile ───────────────────────────────────────────────────── */
.mobile-header {
    display: none;
}

.tab-bar {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-bottom: 5rem;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        background: var(--navy);
        color: #fff;
        position: sticky;
        top: 0;
        z-index: 90;
        margin: -1rem -1rem 1rem -1rem;
    }

    .mobile-header__brand {
        font-weight: 700;
        font-size: 1rem;
    }

    .mobile-header__menu {
        background: none;
        border: none;
        color: #fff;
        font-size: 1.25rem;
        cursor: pointer;
        padding: 0.25rem;
    }

    /* Bottom tab bar */
    .tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        justify-content: space-around;
        padding: 0.375rem 0;
        z-index: 100;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
    }

    .tab-bar__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.15rem;
        color: var(--text-muted);
        font-size: 0.65rem;
        padding: 0.25rem 0.5rem;
        border: none;
        background: none;
        cursor: pointer;
        text-decoration: none;
        transition: color 0.15s;
    }

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

    .tab-bar__icon {
        font-size: 1.25rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .timer-bar {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .timer-bar__info {
        justify-content: center;
    }

    .timer-bar__actions {
        justify-content: center;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar select,
    .toolbar input {
        width: 100%;
        min-width: 0;
    }
}

/* Mobile nav overlay */
.mobile-nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.2s;
}

.mobile-nav-overlay--visible {
    opacity: 1;
}

.mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--navy);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding: 1rem 0;
    overflow-y: auto;
}

.mobile-nav--open {
    transform: translateX(0);
}

.mobile-nav .nav-link {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* ── Report Tabs ─────────────────────────────────────────────────────────────── */
.report-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.report-tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.report-tab:hover {
    color: var(--text);
}

.report-tab--active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

@media (max-width: 768px) {
    .report-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .report-tab {
        white-space: nowrap;
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
}

/* ── Utilisation Bars ──────────────────────────────────────────────────────── */
.util-bar-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 140px;
}

.util-bar {
    height: 8px;
    border-radius: 4px;
    transition: width 0.3s;
    flex-shrink: 0;
    min-width: 4px;
}

.util-on-track { background: var(--success); }
.util-attention { background: var(--warning); }
.util-over { background: var(--danger); }

.util-bar__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Settings — Xero Section ──────────────────────────────────────────────── */
.settings-xero-status {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.settings-xero-status__indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.settings-xero-status__indicator--connected {
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-light);
}

.settings-xero-status__indicator--disconnected {
    background: var(--text-light);
}

.settings-xero-status__label {
    font-weight: 600;
    font-size: 0.95rem;
}

.settings-xero-status__org {
    font-size: 0.85rem;
    color: var(--text);
}

.settings-xero-actions {
    display: flex;
    gap: 0.5rem;
}


/* ── Detail Grid ────────────────────────────────────────────────────────────── */
.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.detail-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    min-width: 120px;
    flex-shrink: 0;
}

/* ── Utilisation Bar Fill ──────────────────────────────────────────────────── */
.util-bar {
    position: relative;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    min-width: 80px;
}

.util-bar__fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.util-bar__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Hide Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
