:root {
  --bg: #f5f5f5;
  --bg-card: #fff;
  --bg-table-hover: #fafafa;
  --bg-table-th: #fafafa;
  --bg-progress: #eee;
  --bg-code: #f0f0f0;
  --bg-input: #fff;
  --bg-flash-success: #d4edda;
  --bg-flash-error: #f8d7da;
  --bg-help-note: #fffbe6;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #888;
  --text-faint: #999;
  --text-nav: #555;
  --border: #e0e0e0;
  --border-light: #ddd;
  --border-table: #eee;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-auth: 0 2px 8px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
  --bg: #121212;
  --bg-card: #1e1e1e;
  --bg-table-hover: #2a2a2a;
  --bg-table-th: #2a2a2a;
  --bg-progress: #333;
  --bg-code: #2d2d2d;
  --bg-input: #2d2d2d;
  --bg-flash-success: #1a3d2b;
  --bg-flash-error: #3d1a1a;
  --bg-help-note: #2d2d1a;
  --text: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #888;
  --text-faint: #666;
  --text-nav: #bbb;
  --border: #333;
  --border-light: #444;
  --border-table: #333;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-auth: 0 2px 8px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; transition: background 0.2s, color 0.2s; }

/* Auth */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { background: var(--bg-card); padding: 2rem; border-radius: 8px; box-shadow: var(--shadow-auth); width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.auth-card h2 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 1.5rem; }
.auth-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-card input, .auth-card select { padding: 0.6rem 0.75rem; border: 1px solid var(--border-light); border-radius: 6px; font-size: 0.95rem; background: var(--bg-input); color: var(--text); }
.auth-card button { padding: 0.6rem; background: #25D366; color: #fff; border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; font-weight: 600; }
.auth-card button:hover { background: #1da851; }
.error { color: #e74c3c; font-size: 0.9rem; margin-bottom: 0.5rem; }
.alt-link { margin-top: 1rem; font-size: 0.9rem; text-align: center; color: var(--text-secondary); }
.alt-link a { color: #25D366; text-decoration: none; }

/* Nav */
nav { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 0 1rem; }
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 52px; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); }
.nav-links { display: flex; gap: 1.25rem; align-items: center; }
.nav-links a { text-decoration: none; color: var(--text-nav); font-size: 0.9rem; }
.nav-links a:hover { color: #25D366; }

/* Main */
main { max-width: 1100px; margin: 2rem auto; padding: 0 1rem; }

/* Nav tz badge */
.tz-badge { font-size: 0.75rem; background: #e8f5e9; color: #2e7d32; padding: 0.15rem 0.5rem; border-radius: 10px; font-weight: 600; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.stat-card { background: var(--bg-card); border-radius: 8px; padding: 1.25rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; }
.stat-number { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); }

/* Tables */
.table-wrap { background: var(--bg-card); border-radius: 8px; box-shadow: var(--shadow-sm); overflow-x: auto; margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.75rem; font-size: 0.9rem; border-bottom: 1px solid var(--border-table); }
th { background: var(--bg-table-th); font-weight: 600; color: var(--text-nav); }
tr:hover { background: var(--bg-table-hover); }

/* Buttons */
.btn { display: inline-flex; align-items: center; padding: 0.45rem 0.9rem; border-radius: 6px; font-size: 0.85rem; text-decoration: none; cursor: pointer; border: none; font-weight: 500; }
.btn-secondary { background: transparent; color: var(--text-nav); border: 1.5px solid var(--border-light); }
.btn-secondary:hover { border-color: #25D366; color: #25D366; }
.actions { display: flex; gap: 0.25rem; align-items: center; flex-wrap: nowrap; white-space: nowrap; }
.actions form { display: inline-flex; margin: 0; padding: 0; }
.actions-divider { width: 1px; height: 1.2rem; background: var(--border-light); margin: 0 0.25rem; flex-shrink: 0; }

/* Filter bar */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.filter-btn { padding: 0.4rem 1rem; border-radius: 20px; font-size: 0.85rem; text-decoration: none; color: var(--text-nav); background: var(--bg-card); border: 1.5px solid var(--border-light); font-weight: 500; transition: 0.15s; }
.filter-btn:hover { border-color: #25D366; color: #25D366; }
.filter-btn.active { background: #25D366; color: #fff; border-color: #25D366; }
.search-input { padding: 0.4rem 0.75rem; border: 1.5px solid var(--border-light); border-radius: 20px; font-size: 0.85rem; background: var(--bg-input); color: var(--text); outline: none; width: 180px; transition: border-color 0.15s; }
.search-input:focus { border-color: #25D366; }
.search-input::placeholder { color: var(--text-faint); }
.search-form { margin-left: auto; display: inline-flex; }

.btn-primary { background: #25D366; color: #fff; }
.btn-primary:hover { background: #1da851; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: #f39c12; color: #fff; }
.btn-warning:hover { background: #d68910; }
.btn-skip { background: #e67e22; color: #fff; }
.btn-skip:hover { background: #cf6d17; }
.btn-clear { background: transparent; color: var(--text-faint); border: 1px solid var(--border-light) !important; padding: 0.3rem 0.45rem; font-size: 0.7rem; line-height: 1; border-radius: 4px; cursor: pointer; }
.btn-clear:hover { background: rgba(231,76,60,0.1); color: #e74c3c; border-color: #e74c3c !important; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Forms */
.form-card { background: var(--bg-card); border-radius: 8px; box-shadow: var(--shadow-sm); padding: 1.5rem; max-width: 520px; margin-top: 1rem; }
.form-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.form-card label { font-weight: 500; font-size: 0.9rem; }
.form-card input, .form-card select, .form-card textarea { padding: 0.5rem 0.7rem; border: 1px solid var(--border-light); border-radius: 6px; font-size: 0.9rem; background: var(--bg-input); color: var(--text); }
.form-card input[type="file"] { padding: 0.3rem; font-size: 0.85rem; }
.form-card textarea { min-height: 80px; resize: vertical; }
.form-card button { align-self: flex-start; }
.form-divider { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0; }

/* Header row */
.header-row { display: flex; align-items: center; gap: 1rem; }
.header-row h1 { flex: 1; }
.header-row a { text-decoration: none; }

/* Status badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge-pending { background: #ffeaa7; color: #6c5b00; }
.badge-active { background: #81ecec; color: #005a5a; }
.badge-completed { background: #55efc4; color: #004d33; }
.badge-failed { background: #fab1a0; color: #6b1a00; }
.badge-paused { background: #dfe6e9; color: #2d3436; }
.badge-trigger { background: #a29bfe; color: #fff; }
.badge-skipped { background: #ffeaa7; color: #6c5b00; }
.skip-badge { display: inline-block; margin-left: 0.35rem; padding: 0.1rem 0.4rem; border-radius: 8px; font-size: 0.7rem; background: #fdebd0; color: #a04000; font-weight: 600; white-space: nowrap; }

/* Flash messages */
.flash { padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash-success { background: var(--bg-flash-success); color: #155724; border: 1px solid #c3e6cb; }
.flash-error { background: var(--bg-flash-error); color: #721c24; border: 1px solid #f5c6cb; }

/* Section */
.section-header { margin-bottom: 0.5rem; }
.section-header h1 { font-size: 1.4rem; }

/* Help page */
.help-page { max-width: 720px; }
.help-page h1 { font-size: 1.5rem; margin-bottom: 1rem; }
.help-page section { background: var(--bg-card); border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.help-page h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.help-page h3 { font-size: 0.95rem; margin: 0.75rem 0 0.35rem; }
.help-page p, .help-page li { font-size: 0.9rem; color: var(--text); line-height: 1.6; }
.help-page ol, .help-page ul { padding-left: 1.25rem; }
.help-page li { margin-bottom: 0.3rem; }
.help-page code { background: var(--bg-code); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.85rem; }
.help-page .note { background: var(--bg-help-note); border: 1px solid #ffe58f; border-radius: 6px; padding: 0.6rem 0.8rem; margin-top: 0.5rem; font-size: 0.85rem; }
.help-page a { color: #25D366; }

/* Dashboard */
.tz-note { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.1rem; }
.tz-note a { color: #25D366; text-decoration: none; }
.stat-card { position: relative; padding-left: 3.5rem; }
.stat-icon { position: absolute; left: 1rem; top: 1.25rem; font-size: 1.5rem; }
.stat-card-jobs { border-left: 4px solid #74b9ff; }
.stat-card-active { border-left: 4px solid #00cec9; }
.stat-card-sent { border-left: 4px solid #00b894; }
.stat-card-failed { border-left: 4px solid #e17055; }
.stat-card-tokens { border-left: 4px solid #6c5ce7; }

.progress-bar-wrap { background: var(--bg-progress); border-radius: 999px; height: 2rem; margin-top: 1rem; position: relative; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); }
.progress-bar { height: 100%; background: linear-gradient(90deg, #25D366, #00b894, #00cec9); border-radius: 999px; transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1); position: relative; overflow: hidden; min-width: 2rem; }
.progress-bar::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent); animation: shimmer 2s infinite; }
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.progress-label { position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%); font-size: 0.8rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
@media (max-width: 768px) { .dashboard-grid { grid-template-columns: 1fr; } }

.dash-section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.dash-section-header h2 { font-size: 1.05rem; }
.mini-table { margin-top: 0; }
.empty-row { border: none !important; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 2.5rem 1rem !important; text-align: center; }
.empty-state-icon { font-size: 2.5rem; line-height: 1; }
.empty-state-text { font-size: 0.95rem; color: var(--text-muted); max-width: 280px; }
.empty-state .btn { margin-top: 0.25rem; }
.empty-state-link { color: #25D366; text-decoration: none; font-weight: 600; }
.empty-state-link:hover { text-decoration: underline; }

/* Footer */
footer { max-width: 1100px; margin: 3rem auto 1.5rem; padding: 0 1rem; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--text-faint); border-top: 1px solid var(--border); padding-top: 1rem; }
.footer-links { display: flex; gap: 1rem; }
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: #25D366; }

/* Lang toggle & clock */
.clock { font-size: 0.8rem; color: var(--text-nav); font-variant-numeric: tabular-nums; }
.lang-form { display: inline-flex; }
.lang-toggle { background: #e8f5e9; color: #2e7d32; border: none; border-radius: 10px; padding: 0.15rem 0.5rem; font-size: 0.75rem; font-weight: 700; cursor: pointer; line-height: 1.5; }
.lang-toggle:hover { background: #c8e6c9; }

/* Theme toggle */
.theme-toggle { background: none; border: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0.15rem; color: var(--text-nav); }
.theme-toggle:hover { color: #25D366; }

/* RTL */
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] .stats { direction: rtl; }
[dir="rtl"] .stat-card { padding-left: 1.25rem; padding-right: 3.5rem; }
[dir="rtl"] .stat-icon { left: auto; right: 1rem; }
[dir="rtl"] .nav-inner { flex-direction: row-reverse; }
[dir="rtl"] .filter-bar { justify-content: flex-end; }
[dir="rtl"] .header-row h1 { text-align: right; }
[dir="rtl"] .progress-label { right: auto; left: 0.5rem; }
[dir="rtl"] .actions { flex-direction: row-reverse; }
[dir="rtl"] .dash-section-header { flex-direction: row-reverse; }
[dir="rtl"] .auth-card { text-align: right; }
[dir="rtl"] .footer-links { flex-direction: row-reverse; }
[dir="rtl"] .checkbox-group { direction: rtl; }
[dir="rtl"] .tz-note { direction: rtl; }
[dir="rtl"] .alt-link { direction: rtl; }
[dir="rtl"] .clock { direction: ltr; display: inline-block; }

.spinner-overlay { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.25); backdrop-filter: blur(1px); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.spinner-overlay.visible { opacity: 1; pointer-events: auto; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--border); border-top-color: #25D366; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-overlay { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal-box { background: var(--bg-card); border-radius: 12px; padding: 1.5rem; max-width: 380px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-message { font-size: 1rem; margin-bottom: 1.25rem; color: var(--text); line-height: 1.5; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 99999; display: flex; flex-direction: column; gap: 0.5rem; max-width: 360px; }
.toast { padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.9rem; cursor: pointer; opacity: 0; transform: translateX(100%); transition: opacity 0.3s, transform 0.3s; }
.toast-visible { opacity: 1; transform: translateX(0); }
.toast-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.toast-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
[data-theme="dark"] .toast-success { background: #1a3d2b; color: #a3d9b1; border-color: #2d6a4f; box-shadow: none; }
[data-theme="dark"] .toast-error { background: #3d1a1a; color: #f5b7b1; border-color: #6b2a2a; box-shadow: none; }
[dir="rtl"] .toast-container { right: auto; left: 1rem; }
[dir="rtl"] .toast { transform: translateX(-100%); }
[dir="rtl"] .toast-visible { transform: translateX(0); }

.msg-toggle { background: none; border: none; cursor: pointer; font-size: 0.7rem; color: var(--text-faint); padding: 0.15rem 0.3rem; transition: transform 0.2s; line-height: 1; }
.msg-toggle:hover { color: #25D366; }
.msg-toggle.open { transform: rotate(90deg); color: #25D366; }
.msg-row { display: none; }
.msg-row.open { display: table-row; }
.msg-content { font-size: 0.85rem; color: var(--text-secondary); background: var(--bg-code); padding: 0.6rem 0.8rem; border-radius: 6px; white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow-y: auto; margin: 0.25rem 0; }

.sort-link { color: var(--text); text-decoration: none; font-weight: 600; }
.sort-link:hover { color: #25D366; }
.sort-icon { font-size: 0.7rem; }

.pagination { display: flex; gap: 0.25rem; justify-content: center; padding: 1rem; align-items: center; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; height: 2rem; padding: 0 0.4rem; border-radius: 6px; font-size: 0.85rem; text-decoration: none; color: var(--text-nav); background: var(--bg-card); border: 1px solid var(--border-light); transition: 0.15s; }
.page-link:hover { border-color: #25D366; color: #25D366; }
.page-link.active { background: #25D366; color: #fff; border-color: #25D366; }
.page-link.disabled { opacity: 0.4; pointer-events: none; }

.next-run-cell { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.onboarding-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; transition: opacity 0.3s; }
.onboarding-card { background: var(--bg-card); border-radius: 12px; padding: 2rem; max-width: 480px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.onboarding-card h2 { margin-top: 0; font-size: 1.25rem; }
.onboarding-steps { margin: 1.5rem 0; }
.onboarding-step { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; font-size: 0.95rem; line-height: 1.4; }
.step-icon { font-size: 1.25rem; flex-shrink: 0; }

.job-id-link { color: var(--primary); text-decoration: none; font-variant-numeric: tabular-nums; }
.job-id-link:hover { text-decoration: underline; }

.detail-grid { display: flex; flex-direction: column; gap: 1.25rem; margin-top: 1.25rem; }
.detail-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-sm); overflow: hidden; }
.detail-card-header { padding: 0.75rem 1rem; font-weight: 600; font-size: 0.9rem; border-bottom: 1px solid var(--border); background: var(--bg-table-th); text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-secondary); }
.detail-body { padding: 1rem; }
.detail-row { display: flex; padding: 0.4rem 0; border-bottom: 1px solid var(--border-table); }
.detail-row:last-child { border-bottom: none; }
.detail-label { flex: 0 0 120px; font-size: 0.85rem; color: var(--text-secondary); }
.detail-value { flex: 1; font-size: 0.9rem; word-break: break-word; }
.detail-message { white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; line-height: 1.6; }
.detail-image { margin-top: 1rem; }
.detail-img { max-width: 100%; max-height: 400px; border-radius: 6px; border: 1px solid var(--border); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.detail-actions form { display: inline; }
