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

:root {
  --bg:        #f5f4f0;
  --surface:   #ffffff;
  --surface2:  #f0efe9;
  --border:    #e2e0d8;
  --border2:   #ccc9be;
  --text:      #1a1917;
  --text2:     #6b6860;
  --text3:     #9e9c94;
  --accent:    #1a1917;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 3px rgba(0,0,0,.08);

  --pending:   #854F0B;
  --pending-bg:#FAEEDA;
  --prog:      #185FA5;
  --prog-bg:   #E6F1FB;
  --done:      #3B6D11;
  --done-bg:   #EAF3DE;
  --urgent:    #A32D2D;
  --urgent-bg: #FCEBEB;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #18181b;
    --surface:  #1f1f23;
    --surface2: #2a2a2e;
    --border:   #333338;
    --border2:  #4a4a52;
    --text:     #f0eff0;
    --text2:    #9a9aa5;
    --text3:    #6b6b75;
    --accent:   #f0eff0;
  }
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.5; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }
.main { flex: 1; padding: 1.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 16px; font-weight: 500; margin-bottom: 1.25rem; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; height: 52px; position: sticky; top: 0; z-index: 100; }
.topbar-logo { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; }
.topbar-nav { display: flex; gap: 4px; margin-left: auto; }
.nav-btn { font-size: 13px; padding: 5px 12px; border: none; background: transparent; color: var(--text2); cursor: pointer; border-radius: var(--radius-sm); transition: all 0.12s; font-family: inherit; }
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--surface2); color: var(--text); font-weight: 500; }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface2); border-radius: var(--radius-sm); padding: 0.85rem 1rem; }
.stat-label { font-size: 11px; color: var(--text2); margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 600; color: var(--text); }
.stat-value.pending { color: var(--pending); }
.stat-value.inprogress { color: var(--prog); }
.stat-value.urgent { color: var(--urgent); }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 1rem; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.filter-chip { font-size: 12px; padding: 4px 11px; border: 1px solid var(--border); background: var(--surface); color: var(--text2); border-radius: 20px; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.filter-chip:hover { border-color: var(--border2); color: var(--text); }
.filter-chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.search-input { font-size: 13px; padding: 6px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-family: inherit; width: 220px; }
.search-input:focus { outline: none; border-color: var(--border2); }

/* ── Job Cards ───────────────────────────────────────────────────────────── */
.jobs-list { display: flex; flex-direction: column; gap: 7px; }
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem 1.1rem; cursor: pointer; transition: border-color 0.12s; display: flex; align-items: center; gap: 12px; }
.job-card:hover { border-color: var(--border2); }
.job-card-id { font-size: 11px; font-weight: 500; font-family: monospace; color: var(--text3); min-width: 68px; }
.job-card-info { flex: 1; min-width: 0; }
.job-card-client { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card-desc { font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card-meta { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.badge-pending    { background: var(--pending-bg); color: var(--pending); }
.badge-inprogress { background: var(--prog-bg);    color: var(--prog); }
.badge-done       { background: var(--done-bg);     color: var(--done); }
.badge-urgent     { background: var(--urgent-bg);   color: var(--urgent); }
.op-dot { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; flex-shrink: 0; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text2); }
.form-input { font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-family: inherit; transition: border-color 0.12s; }
.form-input:focus { outline: none; border-color: var(--border2); }
.textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 8px; margin-top: 1.5rem; }

/* ── Upload ──────────────────────────────────────────────────────────────── */
.upload-zone { border: 1.5px dashed var(--border2); border-radius: var(--radius-sm); padding: 1.5rem; text-align: center; color: var(--text2); font-size: 13px; cursor: pointer; transition: all 0.12s; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); background: var(--surface2); }
.upload-icon { font-size: 22px; margin-bottom: 6px; color: var(--text3); }
.upload-link { color: var(--text); text-decoration: underline; cursor: pointer; }
.upload-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }
.file-preview-list { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.file-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--surface2); border-radius: var(--radius-sm); font-size: 13px; }
.file-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { font-size: 11px; color: var(--text3); white-space: nowrap; }
.file-item-del { background: none; border: none; cursor: pointer; color: var(--text3); font-size: 16px; padding: 0 4px; line-height: 1; }
.file-item-del:hover { color: var(--urgent); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary { font-size: 13px; padding: 7px 18px; background: var(--accent); color: var(--surface); border: none; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; font-weight: 500; transition: opacity 0.12s; }
.btn-primary:hover { opacity: 0.82; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-secondary { font-size: 13px; padding: 7px 14px; background: transparent; color: var(--text2); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; transition: all 0.12s; }
.btn-secondary:hover { border-color: var(--border2); color: var(--text); }
.btn-danger { font-size: 13px; padding: 7px 14px; background: transparent; color: var(--urgent); border: 1px solid var(--urgent-bg); border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; transition: all 0.12s; }
.btn-danger:hover { background: var(--urgent-bg); }

/* ── Drawer ──────────────────────────────────────────────────────────────── */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 200; display: flex; justify-content: flex-end; }
.drawer-overlay.hidden { display: none; }
.drawer { background: var(--surface); width: 460px; max-width: 100vw; height: 100%; display: flex; flex-direction: column; overflow-y: auto; box-shadow: -4px 0 24px rgba(0,0,0,.1); }
.drawer-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.drawer-id { font-size: 11px; font-family: monospace; color: var(--text3); }
.drawer-title { font-size: 15px; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.close-btn { font-size: 20px; background: none; border: none; cursor: pointer; color: var(--text2); line-height: 1; padding: 2px 6px; border-radius: var(--radius-sm); }
.close-btn:hover { background: var(--surface2); }
.drawer-body { padding: 1.25rem; flex: 1; display: flex; flex-direction: column; gap: 1.25rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 11px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.field-value { font-size: 14px; color: var(--text); }
.price-big { font-size: 20px; font-weight: 600; }
.inline-select { font-size: 13px; padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-family: inherit; cursor: pointer; }
.drawer-files { display: flex; flex-direction: column; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--surface2); border-radius: var(--radius-sm); font-size: 13px; }
.file-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-size { font-size: 11px; color: var(--text3); }
.file-row a { font-size: 11px; color: var(--prog); text-decoration: none; white-space: nowrap; }
.file-row a:hover { text-decoration: underline; }
.upload-more { margin-top: 6px; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-wrap { max-width: 620px; display: flex; flex-direction: column; gap: 1rem; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.settings-section-title { font-size: 14px; font-weight: 500; margin-bottom: 1rem; }
.operator-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.operator-row:last-child { border-bottom: none; }
.op-name { flex: 1; font-size: 13px; }
.op-role-text { font-size: 12px; color: var(--text2); }
.add-op-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── Utils ───────────────────────────────────────────────────────────────── */
.loading { padding: 2rem; text-align: center; color: var(--text3); font-size: 13px; }
.empty { padding: 3rem; text-align: center; color: var(--text3); font-size: 13px; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--border); margin: 0; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); font-size: 13px; padding: 8px 18px; border-radius: 20px; z-index: 9999; pointer-events: none; transition: opacity 0.25s; }
.toast.hidden { opacity: 0; }

@media (max-width: 640px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }
  .drawer { width: 100vw; }
  .search-input { width: 100%; }
}
