:root {
  --bg: #121212;
  --surface: #1E1E1E;
  --surface-hi: #2A2A2A;
  --primary: #F57C00;
  --primary-dim: rgba(245,124,0,0.2);
  --primary-dark: #CC5500;
  --secondary: #1976D2;
  --secondary-dim: rgba(25,118,210,0.2);
  --text: #FFFFFF;
  --text2: #9E9E9E;
  --text3: #616161;
  --err: #CF6679;
  --err-bg: rgba(207,102,121,0.15);
  --ok: #4CAF50;
  --divider: rgba(255,255,255,0.08);
  --critical: #D32F2F;
  --high: #F57C00;
  --medium: #FBC02D;
  --low: #388E3C;
  --minor: #757575;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; min-height: 100vh; overflow-x: hidden; }
#app { min-height: 100vh; }
#modal { position: fixed; inset: 0; z-index: 100; display: none; }
#modal.open { display: flex; align-items: center; justify-content: center; }
#toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: 90%; max-width: 400px; }

/* Toast */
.toast { padding: 12px 16px; border-radius: var(--radius-sm); color: #fff; font-size: 14px; text-align: center; animation: slideDown .3s ease; pointer-events: auto; }
.toast.success { background: var(--ok); }
.toast.error { background: var(--err); }
.toast.info { background: var(--secondary); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* ==================== LOGIN ==================== */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 32px 24px; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.login-icon { margin-bottom: 8px; color: var(--primary); }
.login-card h1 { font-size: 28px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.login-card .subtitle { font-size: 14px; color: var(--text2); margin-bottom: 32px; }
.login-error { background: var(--err-bg); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; text-align: left; color: var(--err); font-size: 14px; }
.login-error .close-err { margin-left: auto; background: none; border: none; color: var(--err); cursor: pointer; font-size: 18px; padding: 0 4px; }
.input-group { position: relative; margin-bottom: 16px; }
.input-group svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text2); pointer-events: none; }
.input-group input { width: 100%; padding: 14px 14px 14px 44px; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius); color: var(--text); font-size: 16px; outline: none; }
.input-group input:focus { border-color: var(--primary); }
.input-group .toggle-pw { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text2); cursor: pointer; padding: 4px; }
.btn-primary { width: 100%; padding: 14px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 16px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; }
.btn-primary:disabled { background: var(--text3); cursor: not-allowed; }
.btn-primary:active:not(:disabled) { background: var(--primary-dark); }
.spinner { width: 22px; height: 22px; border: 2.5px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== TOP BAR ==================== */
.top-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--divider); position: sticky; top: 0; z-index: 10; }
.top-bar h1 { font-size: 20px; font-weight: 700; }
.top-bar-info { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.role-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: var(--radius-xs); }
.role-badge.admin { background: var(--primary-dim); color: var(--primary); }
.role-badge.mechanic { background: var(--secondary-dim); color: var(--secondary); }
.top-bar-user { font-size: 12px; color: var(--text2); }
.top-bar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn { background: none; border: none; color: var(--text2); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.icon-btn:active { background: var(--divider); }
.icon-btn.active { color: var(--primary); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; margin: 0 4px; flex-shrink: 0; }
.conn-dot.on { background: var(--ok); }
.conn-dot.off { background: var(--err); }

/* ==================== SEARCH BAR ==================== */
.search-bar { padding: 8px 16px; }
.search-bar .input-group { margin: 0; }
.search-bar input { padding-right: 40px; }
.search-bar .clear-search { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text2); cursor: pointer; padding: 4px; }

/* ==================== STATS ==================== */
.stats-card { display: flex; margin: 12px 16px; background: var(--primary-dim); border-radius: var(--radius); padding: 14px; gap: 8px; }
.stat { flex: 1; text-align: center; }
.stat-val { font-size: 24px; font-weight: 700; }
.stat-val.total { color: var(--primary); }
.stat-val.pending { color: var(--medium); }
.stat-val.done { color: var(--ok); }
.stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; margin-top: 2px; }

/* ==================== SECTIONS ==================== */
.section { padding: 0 16px; margin-bottom: 8px; }
.section-hdr { display: flex; align-items: center; gap: 8px; padding: 12px 0 8px; }
.section-hdr h2 { font-size: 16px; font-weight: 600; }
.section-hdr .count { font-size: 11px; font-weight: 700; background: var(--primary-dim); color: var(--primary); padding: 2px 8px; border-radius: 10px; }
.section-hdr .reorder-hint { font-size: 11px; color: var(--text3); margin-left: auto; }
.task-list { display: flex; flex-direction: column; gap: 6px; }

/* ==================== TASK ITEM ==================== */
.task-item { background: var(--surface); border-radius: var(--radius); padding: 12px; display: flex; align-items: flex-start; gap: 10px; cursor: pointer; transition: background .15s; }
.task-item:active { background: var(--surface-hi); }
.task-item.completed { opacity: 0.55; }
.task-check { flex-shrink: 0; margin-top: 2px; }
.task-check button { background: none; border: none; cursor: pointer; padding: 0; color: var(--text2); }
.task-check .checked { color: var(--primary); }
.priority-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.task-content { flex: 1; min-width: 0; }
.task-title { font-size: 15px; word-break: break-word; }
.task-item.completed .task-title { text-decoration: line-through; color: var(--text2); }
.task-meta { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text3); margin-top: 3px; }
.task-meta svg { flex-shrink: 0; }
.task-desc { font-size: 13px; color: var(--text2); margin-top: 4px; }
.task-attach { font-size: 11px; color: var(--primary); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.task-by { font-size: 11px; color: var(--text3); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.task-completed-by { font-size: 11px; color: var(--primary); opacity: 0.7; margin-top: 3px; }
.task-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.priority-badge { font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: var(--radius-xs); white-space: nowrap; cursor: pointer; position: relative; }
.priority-menu { position: absolute; right: 0; top: 100%; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius-sm); overflow: hidden; z-index: 20; min-width: 120px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.priority-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px; background: none; border: none; color: var(--text); font-size: 13px; cursor: pointer; text-align: left; }
.priority-menu button:active { background: var(--divider); }
.priority-menu .p-dot { width: 10px; height: 10px; border-radius: 50%; }
.admin-btns { display: flex; gap: 2px; }
.admin-btns button { background: none; border: none; cursor: pointer; padding: 4px; border-radius: 4px; color: var(--text3); }
.admin-btns button:active { background: var(--divider); }
.admin-btns button.del { color: var(--critical); }
.admin-btns button:disabled { opacity: 0.2; cursor: default; }
.drag-handle { color: var(--text3); flex-shrink: 0; cursor: grab; padding: 4px 2px; touch-action: none; margin-top: 2px; }
.drag-handle:active { cursor: grabbing; }
.task-item.dragging { background: var(--surface-hi); box-shadow: 0 8px 24px rgba(0,0,0,0.5); z-index: 10; position: relative; opacity: 0.95; transform: scale(1.02); transition: box-shadow .15s, transform .15s; }

/* ==================== FAB ==================== */
.fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; border: none; font-size: 28px; cursor: pointer; box-shadow: 0 4px 16px rgba(245,124,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 9; }
.fab:active { background: var(--primary-dark); }

/* ==================== MODAL OVERLAY ==================== */
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-dialog { position: relative; background: var(--surface); border-radius: 16px; width: 92%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.modal-dialog.full { width: 95%; max-width: 550px; height: 90vh; display: flex; flex-direction: column; }
.modal-hdr { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--primary-dim); border-radius: 16px 16px 0 0; flex-shrink: 0; }
.modal-hdr h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-hdr .close-btn { background: none; border: none; color: var(--text); cursor: pointer; padding: 4px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--divider); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ==================== TABS ==================== */
.tabs { display: flex; border-bottom: 1px solid var(--divider); flex-shrink: 0; }
.tab { flex: 1; padding: 12px; text-align: center; font-size: 14px; font-weight: 500; color: var(--text2); background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ==================== TASK DETAIL ==================== */
.detail-row { margin-bottom: 14px; }
.detail-label { font-size: 12px; font-weight: 500; color: var(--primary); margin-bottom: 4px; text-transform: uppercase; }
.detail-value { font-size: 15px; }
.detail-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text2); margin-bottom: 8px; }
.detail-status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: var(--radius-xs); }
.detail-status.done { background: rgba(76,175,80,0.15); color: var(--ok); }
.detail-status.pending { background: var(--primary-dim); color: var(--primary); }
.detail-photos { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.detail-photo { width: 100%; border-radius: var(--radius-sm); max-height: 400px; object-fit: contain; background: var(--bg); }
.assign-select { width: 100%; padding: 10px 12px; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none; }
.assign-select:focus { border-color: var(--primary); }
.btn-assign { background: var(--primary-dim); color: var(--primary); border: none; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; margin-top: 6px; }
.btn-assign:active { background: var(--primary); color: #fff; }
.btn-photo { width: 100%; padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; }
.btn-photo:active { background: var(--primary-dark); }

/* ==================== NOTES ==================== */
.note-form { display: flex; gap: 8px; margin-bottom: 16px; }
.note-form input { flex: 1; padding: 10px 12px; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none; }
.note-form input:focus { border-color: var(--primary); }
.note-form button { background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm); padding: 10px 14px; cursor: pointer; flex-shrink: 0; }
.note-form button:disabled { background: var(--text3); cursor: not-allowed; }
.note-card { background: var(--surface-hi); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.note-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.note-user { font-size: 13px; font-weight: 600; color: var(--primary); }
.note-del { background: none; border: none; color: var(--text3); cursor: pointer; padding: 2px; }
.note-body { font-size: 14px; }
.note-date { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ==================== HISTORY ==================== */
.hist-item { display: flex; gap: 10px; background: var(--surface-hi); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.hist-icon { flex-shrink: 0; color: var(--primary); margin-top: 2px; }
.hist-text { font-size: 13px; }
.hist-detail { font-size: 12px; color: var(--text2); margin-top: 2px; }
.hist-date { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ==================== ADD TASK FORM ==================== */
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; }
.form-field input, .form-field textarea, .form-field select { width: 100%; padding: 10px 12px; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none; font-family: inherit; }
.form-field input:focus, .form-field textarea:focus, .form-field select:focus { border-color: var(--primary); }
.form-field textarea { resize: vertical; min-height: 60px; }
.priority-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.p-chip { padding: 6px 12px; border-radius: 16px; font-size: 12px; font-weight: 600; border: 1px solid var(--divider); background: none; color: var(--text2); cursor: pointer; }
.p-chip.selected { color: #fff; border-color: transparent; }
.p-chip[data-p="1"].selected { background: var(--critical); }
.p-chip[data-p="2"].selected { background: var(--high); }
.p-chip[data-p="3"].selected { background: var(--medium); color: #000; }
.p-chip[data-p="4"].selected { background: var(--low); }
.p-chip[data-p="5"].selected { background: var(--minor); }
.photo-previews { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; margin-top: 8px; }
.photo-preview { position: relative; width: 80px; height: 80px; border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .remove-photo { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--critical); color: #fff; border: none; font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.photo-count { font-size: 12px; color: var(--text2); margin-top: 4px; }
.btn-outline { padding: 10px 16px; background: none; border: 1px solid var(--primary); color: var(--primary); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.btn-outline:active { background: var(--primary-dim); }

/* ==================== USER MANAGEMENT ==================== */
.user-card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.user-icon { color: var(--text2); flex-shrink: 0; }
.user-icon.is-admin { color: var(--primary); }
.user-info { flex: 1; }
.user-name { font-size: 15px; font-weight: 600; }
.user-role { font-size: 12px; color: var(--text3); }
.user-you { font-size: 12px; color: var(--text3); font-style: italic; }
.user-actions { display: flex; gap: 4px; }
.user-actions button { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 4px; color: var(--text2); }
.user-actions button:active { background: var(--divider); }
.user-actions button.del { color: var(--critical); }

/* ==================== BUTTONS ==================== */
.btn { padding: 10px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; cursor: pointer; border: none; }
.btn-ok { background: var(--primary); color: #fff; }
.btn-ok:active { background: var(--primary-dark); }
.btn-ok:disabled { background: var(--text3); cursor: not-allowed; }
.btn-cancel { background: none; color: var(--text2); }
.btn-cancel:active { background: var(--divider); }
.btn-danger { background: var(--critical); color: #fff; }
.btn-danger:active { background: #b71c1c; }

/* ==================== EMPTY & LOADING ==================== */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state svg { color: var(--primary); opacity: 0.5; margin-bottom: 12px; }
.empty-state h3 { font-size: 20px; margin-bottom: 4px; }
.empty-state p { font-size: 14px; color: var(--text2); }
.empty-state .hint { color: var(--primary); font-size: 12px; margin-top: 4px; }
.loading-center { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px; gap: 12px; color: var(--text2); font-size: 14px; }

/* ==================== CONFIRM DIALOG ==================== */
.confirm-body { padding: 24px 20px; }
.confirm-body h3 { font-size: 18px; margin-bottom: 8px; }
.confirm-body p { font-size: 14px; color: var(--text2); }

/* ==================== PHOTO SOURCE DIALOG ==================== */
.photo-source { display: flex; gap: 12px; padding: 20px; }
.photo-source button { flex: 1; padding: 16px; background: var(--surface-hi); border: 1px solid var(--divider); border-radius: var(--radius); cursor: pointer; color: var(--text); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; }
.photo-source button:active { border-color: var(--primary); background: var(--primary-dim); }
.photo-source button svg { color: var(--primary); }

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text3); border-radius: 2px; }

/* ==================== CONTENT PADDING ==================== */
.content-pad { padding-bottom: 80px; }

/* ==================== ROLE CHIPS IN FORM ==================== */
.role-chips { display: flex; gap: 8px; }
.role-chip { padding: 8px 16px; border-radius: 16px; font-size: 13px; border: 1px solid var(--divider); background: none; color: var(--text2); cursor: pointer; }
.role-chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.form-error { color: var(--err); font-size: 12px; margin-top: 4px; }
