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

:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --success: #27ae60;
    --danger: #e74c3c;
    --warn: #f39c12;
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #dcdde1;
    --radius: 12px;
    --font-size: 20px;
    --font-size-lg: 24px;
    --font-size-xl: 28px;
}

/* ===== Dark Mode ===== */
body.dark {
    --primary: #1a1a2e;
    --accent: #4fa3e0;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warn: #f39c12;
    --bg: #121212;
    --card: #1e1e1e;
    --text: #e0e0e0;
    --text-light: #999999;
    --border: #333333;
}

body.dark #tab-bar {
    background: #1a1a2e;
}

body.dark .confirm-box {
    background: var(--card);
    color: var(--text);
}

body.dark input,
body.dark select {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
}

/* Dark mode toggle */
.dark-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.dark-toggle-label {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.toggle-switch {
    position: relative;
    width: 56px;
    height: 30px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 30px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    top: 3px;
    right: 3px;
    transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(-26px);
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-size: var(--font-size);
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    text-align: right;
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

/* ===== Tab Navigation (Bottom) ===== */
#tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--primary);
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 14px;
    padding: 6px 4px;
    cursor: pointer;
    transition: color 0.2s;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.tab-icon {
    font-size: 28px;
    line-height: 1;
}

.tab-label {
    font-size: 11px;
}

.tab-btn.active {
    color: #fff;
    font-weight: bold;
}

/* ===== Pages ===== */
.page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(70px + max(6px, env(safe-area-inset-bottom))); /* tab bar height */
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page.active {
    display: flex;
    flex-direction: column;
}

.page h1 {
    font-size: var(--font-size-xl);
    margin-bottom: 12px;
    color: var(--primary);
    flex-shrink: 0;
}

/* ===== Form ===== */
.form-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.form-row label {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 3px;
}

.form-row input,
.form-row select {
    font-size: var(--font-size-lg);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    direction: rtl;
    text-align: right;
    width: 100%;
    transition: border-color 0.2s;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row input[type="date"] {
    font-family: inherit;
}

.date-picker-wrap {
    position: relative;
    width: 100%;
}

.date-picker-wrap #job-date-display {
    width: 100%;
    cursor: pointer;
    font-size: var(--font-size-lg);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    direction: ltr;
    text-align: center;
    font-weight: 600;
    letter-spacing: 1px;
}

.date-picker-wrap .date-hidden {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
    -webkit-appearance: none;
}

.autocomplete-wrap {
    position: relative;
    width: 100%;
}

.period-selects {
    display: flex;
    gap: 10px;
}

.period-selects select {
    flex: 1;
    font-size: var(--font-size-lg);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
    font-size: var(--font-size-lg);
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: bold;
    transition: opacity 0.2s, transform 0.1s;
    flex: 1;
}

.btn:active {
    transform: scale(0.97);
}

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

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

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

.btn-small {
    font-size: 16px;
    padding: 8px 16px;
    flex: none;
}

/* ===== Search ===== */
.search-row {
    margin-bottom: 10px;
    flex-shrink: 0;
}

.search-row input {
    font-size: var(--font-size-lg);
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    width: 100%;
    direction: rtl;
    text-align: right;
}

.search-row input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ===== Job List ===== */
.job-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.job-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s;
}

.job-card:active {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.job-card-info {
    flex: 1;
}

.job-card-client {
    font-size: var(--font-size-lg);
    font-weight: bold;
}

.job-card-desc {
    font-size: 16px;
    color: var(--text-light);
    margin-top: 2px;
}

.job-card-price {
    font-size: var(--font-size-xl);
    font-weight: bold;
    color: var(--success);
    white-space: nowrap;
    margin-right: 12px;
    transition: color 0.2s;
}

.job-card-price.unpayed {
    color: var(--danger);
}

.job-card-price.zero-price {
    color: var(--warn);
}

.job-card-date {
    font-size: 14px;
    color: var(--text-light);
}

.job-card-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.job-card-flags {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ===== Flag Chips (on cards & action overlay) ===== */
.flag-chip {
    font-size: 14px;
    padding: 4px 12px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-user-select: none;
    user-select: none;
    font-weight: 600;
    white-space: nowrap;
}

.flag-chip:active {
    transform: scale(0.95);
}

.flag-chip.flag-done.on {
    background: #d4edda;
    border-color: var(--success);
    color: #155724;
}

.flag-chip.flag-payed.on {
    background: #cce5ff;
    border-color: var(--accent);
    color: #004085;
}

body.dark .flag-chip.flag-done.on {
    background: #1b4332;
    border-color: var(--success);
    color: #95d5b2;
}

body.dark .flag-chip.flag-payed.on {
    background: #0c2d48;
    border-color: var(--accent);
    color: #90caf9;
}

/* ===== Flag Toggles (on form) ===== */
.form-flags {
    display: flex;
    flex-direction: row;
    gap: 12px;
}

.flag-toggle {
    flex: 1;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.flag-toggle input {
    display: none;
}

.flag-pill {
    display: block;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text-light);
    transition: all 0.2s;
}

.flag-toggle input:checked + .flag-pill.flag-done {
    background: #d4edda;
    border-color: var(--success);
    color: #155724;
}

.flag-toggle input:checked + .flag-pill.flag-payed {
    background: #cce5ff;
    border-color: var(--accent);
    color: #004085;
}

body.dark .flag-toggle input:checked + .flag-pill.flag-done {
    background: #1b4332;
    border-color: var(--success);
    color: #95d5b2;
}

body.dark .flag-toggle input:checked + .flag-pill.flag-payed {
    background: #0c2d48;
    border-color: var(--accent);
    color: #90caf9;
}

/* ===== Action overlay flags ===== */
.action-flags {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

/* ===== Card action buttons ===== */
.card-actions-spacer {
    flex: 1;
}

.card-action-btn {
    font-size: 18px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    padding: 0;
}

.card-action-btn:active {
    transform: scale(0.9);
}

.card-edit:hover {
    background: #cce5ff;
}

.card-delete:hover {
    background: #f8d7da;
}

body.dark .card-action-btn {
    background: #2a2a2a;
}

body.dark .card-edit:hover {
    background: #0c2d48;
}

body.dark .card-delete:hover {
    background: #3d1f1f;
}

.job-card-actions {
    display: flex;
    gap: 8px;
    margin-right: 8px;
}

/* ===== Reports ===== */
.summary-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.summary-total {
    font-size: var(--font-size-xl);
    font-weight: bold;
    color: var(--success);
    text-align: center;
    margin-bottom: 8px;
}

.summary-count {
    font-size: var(--font-size);
    text-align: center;
    color: var(--text-light);
}

.report-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.report-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.report-row-name {
    font-size: var(--font-size);
    font-weight: 600;
}

.report-row-amount {
    font-size: var(--font-size-lg);
    font-weight: bold;
    color: var(--success);
}

.report-row-count {
    font-size: 14px;
    color: var(--text-light);
}

.report-row-header {
    cursor: pointer;
    transition: background 0.2s;
}

.report-row-header:active {
    background: var(--bg);
}

.expand-icon {
    font-size: 14px;
    color: var(--text-light);
    margin-right: 4px;
}

.report-client-section {
    margin-bottom: 4px;
}

.report-client-jobs {
    padding: 0 8px;
}

.report-client-jobs.hidden {
    display: none;
}

.report-job-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 4px;
}

.report-job-info {
    display: flex;
    flex-direction: column;
}

.report-job-name {
    font-size: 17px;
    color: var(--text);
}

.report-job-date {
    font-size: 13px;
    color: var(--text-light);
}

.report-job-price {
    font-size: var(--font-size);
    font-weight: 600;
    color: var(--success);
    white-space: nowrap;
}

/* ===== Settings ===== */
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.settings-actions .btn {
    flex: none;
}

.settings-info {
    font-size: 16px;
    color: var(--text-light);
    line-height: 1.5;
}

.auto-backup-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.auto-backup-section h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: calc(74px + max(6px, env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 600;
    z-index: 200;
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    white-space: nowrap;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: var(--font-size);
}

/* ===== Login Screen ===== */
.login-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    overflow-y: auto;
}

.login-screen.hidden {
    display: none;
}

.login-box {
    text-align: center;
    padding: 32px 24px;
    max-width: 380px;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.login-box .form-row {
    text-align: right;
}

.login-box .form-row input {
    text-align: left;
}

.login-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-box h1 {
    font-size: var(--font-size-xl);
    color: var(--primary);
    margin-bottom: 8px;
}

body.dark .login-box h1 {
    color: var(--text);
}

.login-subtitle {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 16px;
    min-height: 20px;
}

.login-error {
    color: var(--danger);
    font-size: 16px;
    font-weight: 600;
    min-height: 24px;
    margin-bottom: 12px;
}

.login-box .btn {
    flex: none;
}

.login-box .btn:disabled {
    opacity: 0.5;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 16px;
    margin-top: 16px;
    padding: 8px;
    cursor: pointer;
}

/* ===== Error Box ===== */
.error-box {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    background: var(--danger);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    white-space: pre-line;
    direction: rtl;
    z-index: 1000;
    cursor: pointer;
}

.error-box.hidden {
    display: none;
}

.app-version {
    margin-top: 24px;
    text-align: center;
    font-size: 13px;
}

/* ===== Statements (monthly report actions + dialogs) ===== */
.sent-badge {
    font-size: 13px;
    color: var(--success);
    font-weight: 600;
    margin-top: 2px;
}

.report-actions {
    display: flex;
    gap: 8px;
    margin: 4px 0 8px;
}

.report-actions {
    flex-wrap: wrap;
}

.report-actions .btn {
    flex: 1 1 40%;
}

.dialog-box {
    max-height: 90vh;
    overflow-y: auto;
}

.dialog-box .choice-btn,
.dialog-box .dialog-link,
.dialog-form .btn {
    display: block;
    width: calc(100% - 8px);
    text-decoration: none;
    text-align: center;
}

.choice-sub {
    display: block;
    font-size: 13px;
    font-weight: normal;
    opacity: 0.85;
    direction: ltr;
}

.dialog-form .form-row {
    text-align: right;
}

.dialog-form .form-row input {
    font-size: 18px;
}

.dialog-form .form-row input[dir="ltr"] {
    text-align: left;
}

.dialog-error {
    color: var(--danger);
    font-size: 15px !important;
    font-weight: 600;
    min-height: 20px;
    margin-bottom: 8px !important;
}

/* ===== Reminder banner (Tax Authority connection) ===== */
.notice-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff4e0;
    border: 2px solid var(--warn);
    color: #7a4a00;
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 15px;
    flex-shrink: 0;
}

.notice-banner .btn {
    flex: none;
    white-space: nowrap;
}

.receipt-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 10px;
    background: #fff3e0;
    color: #b45309;
    white-space: nowrap;
}

body.dark .receipt-badge {
    background: #4a2c0a;
    color: #ffb74d;
}

.receipts-due-title {
    font-size: 17px;
    margin: 4px 0 8px;
    color: var(--warn);
}

.receipt-due-card {
    border: 2px solid var(--warn);
}

#btn-push-on.hidden,
#btn-push-off.hidden,
#btn-push-test.hidden {
    display: none;
}

.doc-tabs {
    display: flex;
    gap: 8px;
    margin: 4px 0 10px;
}

.doc-tab {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.doc-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

body.dark .doc-tab.active {
    background: var(--accent);
    border-color: var(--accent);
}

.doc-sends {
    color: var(--text-light);
    font-size: 14px;
}

body.dark .notice-banner {
    background: #3a2a10;
    color: #ffd699;
}

.notice-banner.hidden {
    display: none;
}

.doc-badge.refused {
    color: var(--danger);
}

.doc-state {
    font-size: 14px;
    color: var(--text-light);
}

.cash-note {
    color: var(--warn);
    font-size: 15px !important;
    font-weight: 600;
}

/* ===== Invoice mark on a job (every view) ===== */
.inv-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 10px;
    margin-inline-start: 6px;
    white-space: nowrap;
    vertical-align: middle;
}

.inv-badge.on {
    background: #e3f0fb;
    color: #1f5f99;
}

.inv-badge.off {
    background: var(--bg);
    color: var(--text-light);
    border: 1px solid var(--border);
}

body.dark .inv-badge.on {
    background: #0c2d48;
    color: #90caf9;
}

/* ===== Invoices page ===== */
.invoices-summary {
    flex-shrink: 0;
    margin-bottom: 8px;
}

.invoice-card .job-card-main {
    align-items: flex-start;
}

.invoice-card.cancelled {
    opacity: 0.6;
}

.invoice-jobs {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 15px;
    color: var(--text-light);
}

.month-actions-title {
    margin-top: 12px;
    font-weight: 600;
}

/* Seven tabs: a little narrower labels */
.tab-label {
    white-space: nowrap;
}

/* ===== Clients page ===== */
.new-client-btn {
    flex-shrink: 0;
    margin-bottom: 10px;
}

.client-card .job-card-main {
    align-items: flex-start;
}

.client-edit {
    font-size: 20px;
    padding: 4px 8px;
}

.missing {
    color: var(--warn);
}

/* ===== Tax documents ===== */
.doc-badge {
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
    margin-top: 2px;
}

.doc-badge.pending {
    color: var(--warn);
}

.invoiced-chip {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    align-self: center;
}

.flag-chip:disabled {
    opacity: 0.6;
    cursor: default;
}

.dialog-lines {
    font-size: 15px !important;
    text-align: right;
    color: var(--text-light);
    max-height: 160px;
    overflow-y: auto;
}

.dialog-warning {
    color: var(--danger);
    font-size: 15px !important;
    font-weight: 600;
}

.doc-block {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-bottom: 12px;
}

.doc-block p {
    font-size: 17px !important;
    margin-bottom: 8px !important;
}

/* ===== Statement preview (inside the app) ===== */
.preview-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 400;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    padding-top: env(safe-area-inset-top);
}

.preview-bar {
    display: flex;
    justify-content: flex-start;
    padding: 8px 12px;
    background: var(--primary);
    flex-shrink: 0;
}

.preview-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #f5f6fa;
}

/* ===== Delete confirmation ===== */
.confirm-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.confirm-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 320px;
    width: 90%;
    text-align: center;
}

.confirm-box p {
    font-size: var(--font-size-lg);
    margin-bottom: 20px;
}

.confirm-box .btn {
    margin: 4px;
}
