:root {
    --primary: #1565C0;
    --primary-light: #1976D2;
    --success: #2E7D32;
    --danger: #C62828;
    --warning: #F57F17;
    --bg: #F5F5F5;
    --surface: #FFFFFF;
    --text: #212121;
    --text-secondary: #757575;
    --border: #E0E0E0;
    /* iOS safe area insets */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    /* Prevent pull-to-refresh in standalone PWA */
    overscroll-behavior-y: contain;
}

#app {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
    padding-right: var(--sar);
}

.page {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* Login */
.login-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 24px;
}

.login-container h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 32px;
    font-size: 28px;
}

.build-stamp {
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 24px;
}

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

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

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--surface);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.2);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}

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

.btn-primary:hover { background: var(--primary-light); }
.btn-primary:disabled { background: #90CAF9; cursor: not-allowed; }

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

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

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
    width: auto;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

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

/* Status badges */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-draft { background: #E3F2FD; color: #1565C0; }
.badge-submitted { background: #FFF3E0; color: #E65100; }
.badge-approved { background: #E8F5E9; color: #2E7D32; }
.badge-rejected { background: #FFEBEE; color: #C62828; }
.badge-posted { background: #F3E5F5; color: #7B1FA2; }

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 16px;
}

.toolbar h2 {
    font-size: 20px;
}

/* Search */
.search-bar {
    margin-bottom: 16px;
}

.search-bar input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 16px;
    background: var(--surface);
}

/* Detail view */
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.detail-value {
    font-weight: 500;
    text-align: right;
}

.action-bar {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    position: sticky;
    bottom: 0;
    background: var(--bg);
}

.action-bar .btn {
    flex: 1;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: none;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--danger);
    color: white;
    font-size: 12px;
    font-weight: 600;
}

/* Loading */
.loading {
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
}

/* Error */
.error {
    background: #FFEBEE;
    color: var(--danger);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* Connection indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.connection-dot.connected { background: var(--success); }
.connection-dot.disconnected { background: var(--danger); }

/* Amount formatting */
.amount {
    font-family: 'SF Mono', 'Fira Code', monospace;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* QR Scanner */
.qr-scanner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(24px + var(--sat));
    padding-bottom: calc(24px + var(--sab));
}

.qr-scanner-overlay video {
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.qr-scanner-overlay .scanner-title {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.qr-scanner-overlay .scanner-hint {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    margin-top: 16px;
    text-align: center;
}

.qr-code-input {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    width: 100%;
    max-width: 400px;
}

.qr-code-input input {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.qr-code-input input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.divider-text {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    margin: 16px 0;
}

/* Login QR scan button */
.qr-login-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: rgba(21, 101, 192, 0.08);
}

.btn-outline-light {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
}

/* Hamburger menu button */
.menu-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

/* Menu backdrop */
.menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 900;
}

/* Slide-out drawer */
.menu-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--surface);
    z-index: 901;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    padding-top: var(--sat);
    padding-bottom: var(--sab);
}

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

.menu-items {
    flex: 1;
    padding: 8px 0;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 14px 20px;
    background: none;
    border: none;
    text-align: left;
    font-size: 15px;
    color: var(--text);
    cursor: pointer;
}

.menu-item:active {
    background: var(--bg);
}

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

/* ── Step wizard ─────────────────────────────────────────────────────────── */

.stepper {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 8px;
}

.step-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.step-dot.active  { background: var(--primary); color: white; }
.step-dot.done    { background: var(--success);  color: white; }
.step-dot.pending { background: var(--border);   color: var(--text-secondary); }

.step-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    transition: background 0.2s;
}

.step-line.done { background: var(--success); }

/* ── Autocomplete ─────────────────────────────────────────────────────────── */

.autocomplete {
    position: relative;
}

.autocomplete input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--surface);
}

.autocomplete input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.2);
}

.autocomplete-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:active     { background: var(--bg); }

.autocomplete-loading,
.autocomplete-empty {
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.selected-value {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: rgba(21, 101, 192, 0.04);
    font-size: 14px;
}

.clear-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

/* ── Line editor ─────────────────────────────────────────────────────────── */

.line-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
}

.line-card .form-group {
    margin-bottom: 10px;
}

.line-card .form-group:last-of-type {
    margin-bottom: 0;
}

.line-row {
    display: flex;
    gap: 10px;
}

.line-card input[type="number"],
.line-card select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--surface);
    -moz-appearance: textfield;
}

.line-card input[type="number"]::-webkit-outer-spin-button,
.line-card input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

/* ── Floating action button ──────────────────────────────────────────────── */

.fab {
    position: fixed;
    bottom: calc(24px + var(--sab));
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(21, 101, 192, 0.45);
    cursor: pointer;
    border: none;
    z-index: 50;
    transition: background 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.fab:active {
    background: var(--primary-light);
    box-shadow: 0 2px 8px rgba(21, 101, 192, 0.4);
}
