/* ============================================================
   Servico360 — Design System
   Mobile-first, CSS custom properties, no framework
   ============================================================ */

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100dvh; }
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Brand */
  --brand:        #1E3A5F;
  --brand-mid:    #2563EB;
  --brand-light:  #EFF6FF;
  --accent:       #F97316;
  --accent-light: #FFF7ED;

  /* Semantic */
  --success:      #10B981;
  --success-light:#ECFDF5;
  --warning:      #F59E0B;
  --warning-light:#FFFBEB;
  --danger:       #EF4444;
  --danger-light: #FEF2F2;
  --info:         #3B82F6;
  --info-light:   #EFF6FF;

  /* Neutrals */
  --bg:           #F8FAFC;
  --surface:      #FFFFFF;
  --surface-2:    #F1F5F9;
  --border:       #E2E8F0;
  --border-dark:  #CBD5E1;
  --text:         #1E293B;
  --text-2:       #64748B;
  --text-3:       #94A3B8;

  /* OS Status colours */
  --status-pending:       #6B7280;
  --status-scheduled:     #3B82F6;
  --status-in-progress:   #F59E0B;
  --status-completed:     #10B981;
  --status-cancelled:     #EF4444;
  --status-waiting-parts: #8B5CF6;

  /* Priority colours */
  --priority-low:    #6B7280;
  --priority-normal: #3B82F6;
  --priority-high:   #F59E0B;
  --priority-urgent: #EF4444;

  /* Spacing */
  --sp-1: 4px;  --sp-2: 8px;   --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px;  --sp-8: 32px;  --sp-10: 40px;

  /* Radius */
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-xl: 24px; --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 2px 12px rgba(0,0,0,.05);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.12);

  /* Transitions */
  --t-fast: 150ms ease; --t-mid: 250ms ease;

  /* Layout */
  --navbar-h: 60px;
  --sidebar-w: 240px;
  --content-max: 960px;
}

/* ── Splash Screen ─────────────────────────────────────────── */
.splash-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100dvh; gap: var(--sp-6);
}
.splash-brand { font-size: 2rem; font-weight: 800; color: var(--brand); letter-spacing: -1px; }
.splash-brand span { color: var(--brand-mid); }
.splash-spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--brand-mid); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.5px; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.text-sm  { font-size: .875rem; }
.text-xs  { font-size: .75rem; }
.text-muted { color: var(--text-2); }
.fw-bold   { font-weight: 700; }
.fw-semi   { font-weight: 600; }

/* ── Layout ────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--navbar-h); background: var(--brand);
  display: flex; align-items: center; padding: 0 var(--sp-4);
  gap: var(--sp-3); box-shadow: var(--shadow);
}
.navbar-brand { color: #fff; font-weight: 800; font-size: 1.1rem; flex: 1; }
.navbar-brand span { color: #93C5FD; }
.navbar-icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: #fff; opacity: .85; transition: opacity var(--t-fast), background var(--t-fast);
}
.navbar-icon-btn:hover { opacity: 1; background: rgba(255,255,255,.1); }

/* Bottom navigation (mobile) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: var(--sp-2) 0; color: var(--text-2); font-size: .65rem;
  transition: color var(--t-fast); position: relative;
}
.bottom-nav-item.active { color: var(--brand-mid); }
.bottom-nav-item .icon { width: 24px; height: 24px; }
.badge {
  position: absolute; top: 4px; right: calc(50% - 16px);
  background: var(--danger); color: #fff; font-size: .6rem;
  font-weight: 700; border-radius: var(--r-full);
  min-width: 16px; height: 16px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

/* Main content area */
.main-content {
  margin-top: var(--navbar-h);
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
  flex: 1;
}
.page { display: none; }
.page.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-body { padding: var(--sp-4); }
.card-header {
  padding: var(--sp-4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

/* ── OS Card ────────────────────────────────────────────────── */
.os-card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: var(--sp-3);
  border-left: 4px solid var(--border); transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.os-card:active { transform: scale(.99); }
.os-card[data-priority="urgent"]  { border-left-color: var(--priority-urgent); }
.os-card[data-priority="high"]    { border-left-color: var(--priority-high); }
.os-card[data-priority="normal"]  { border-left-color: var(--priority-normal); }
.os-card[data-priority="low"]     { border-left-color: var(--priority-low); }

.os-card-head { padding: var(--sp-3) var(--sp-4); display: flex; gap: var(--sp-3); align-items: flex-start; }
.os-card-info { flex: 1; min-width: 0; }
.os-card-code { font-size: .7rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; }
.os-card-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.os-card-meta  { font-size: .8rem; color: var(--text-2); margin-top: 2px; }
.os-card-actions { padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--border); display: flex; gap: var(--sp-2); }

/* ── Status Badge ───────────────────────────────────────────── */
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--r-full);
  font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.status-badge.pending       { background: #F3F4F6; color: var(--status-pending); }
.status-badge.scheduled     { background: var(--info-light); color: var(--status-scheduled); }
.status-badge.in_progress   { background: var(--warning-light); color: var(--status-in-progress); }
.status-badge.completed     { background: var(--success-light); color: var(--status-completed); }
.status-badge.cancelled     { background: var(--danger-light); color: var(--status-cancelled); }
.status-badge.waiting_parts { background: #F5F3FF; color: var(--status-waiting-parts); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 10px 18px; border-radius: var(--r-md); font-weight: 600; font-size: .9rem;
  transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary   { background: var(--brand-mid); color: #fff; }
.btn-primary:hover { background: #1D4ED8; }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-outline   { background: transparent; color: var(--brand-mid); border: 1.5px solid var(--brand-mid); }
.btn-sm        { padding: 6px 12px; font-size: .8rem; border-radius: var(--r-sm); }
.btn-xs        { padding: 4px 8px; font-size: .75rem; border-radius: var(--r-sm); }
.btn-full      { width: 100%; }
.btn-icon      { width: 36px; height: 36px; padding: 0; border-radius: var(--r-md); }

/* FAB */
.fab {
  position: fixed; bottom: calc(68px + env(safe-area-inset-bottom)); right: var(--sp-4);
  width: 52px; height: 52px; border-radius: var(--r-full);
  background: var(--brand-mid); color: #fff; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 300; transition: transform var(--t-fast), box-shadow var(--t-fast);
  z-index: 90;
}
.fab:hover { transform: scale(1.05); box-shadow: 0 6px 24px rgba(37,99,235,.4); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--sp-4); }
.form-label { display: block; font-size: .85rem; font-weight: 600; color: var(--text); margin-bottom: var(--sp-2); }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--r-md); background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast); outline: none;
  font-size: .95rem;
}
.form-control:focus { border-color: var(--brand-mid); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-control.is-error { border-color: var(--danger); }
.form-error { font-size: .78rem; color: var(--danger); margin-top: var(--sp-1); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748B' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* Tags / Chips */
.tags-input-container { border: 1.5px solid var(--border); border-radius: var(--r-md); padding: var(--sp-2); display: flex; flex-wrap: wrap; gap: var(--sp-1); min-height: 44px; cursor: text; }
.tags-input-container:focus-within { border-color: var(--brand-mid); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-light); color: var(--brand-mid); border-radius: var(--r-full); padding: 2px 10px; font-size: .8rem; font-weight: 600; }
.tag-chip button { color: var(--brand-mid); opacity: .6; font-size: 1rem; line-height: 1; }
.tag-chip button:hover { opacity: 1; }
.tags-input { border: none; outline: none; background: none; font: inherit; font-size: .875rem; min-width: 100px; flex: 1; }

/* ── Sections and pages ─────────────────────────────────────── */
.page-header {
  padding: var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: var(--navbar-h); z-index: 50;
}
.page-header h2 { font-size: 1.1rem; }

.section { padding: var(--sp-4); }
.section + .section { padding-top: 0; }

/* Search bar */
.search-bar { display: flex; gap: var(--sp-2); }
.search-input { flex: 1; position: relative; }
.search-input .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-input input { padding-left: 36px; }
.filter-btn { flex-shrink: 0; }

/* ── Lists ──────────────────────────────────────────────────── */
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); background: var(--surface);
  border-bottom: 1px solid var(--border); transition: background var(--t-fast);
  cursor: pointer;
}
.list-item:hover { background: var(--surface-2); }
.list-item:last-child { border-bottom: none; }
.list-item-info { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: .8rem; color: var(--text-2); margin-top: 1px; }
.avatar { width: 40px; height: 40px; border-radius: var(--r-full); background: var(--brand-light); color: var(--brand-mid); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; flex-shrink: 0; }

/* ── Dashboard Stats ────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
.stat-card { background: var(--surface); border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--shadow); }
.stat-card-value { font-size: 2rem; font-weight: 800; color: var(--brand); line-height: 1; }
.stat-card-label { font-size: .78rem; color: var(--text-2); margin-top: var(--sp-1); font-weight: 500; }
.stat-card.success .stat-card-value { color: var(--success); }
.stat-card.warning .stat-card-value { color: var(--warning); }
.stat-card.danger  .stat-card-value { color: var(--danger); }

/* Financial summary */
.finance-row { display: flex; gap: var(--sp-3); }
.finance-item { flex: 1; padding: var(--sp-3); background: var(--surface); border-radius: var(--r-md); border-left: 4px solid var(--border); }
.finance-item.income  { border-left-color: var(--success); }
.finance-item.expense { border-left-color: var(--danger); }
.finance-item.balance { border-left-color: var(--brand-mid); }
.finance-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 600; }
.finance-value { font-size: 1.1rem; font-weight: 700; margin-top: 2px; }
.finance-item.income .finance-value  { color: var(--success); }
.finance-item.expense .finance-value { color: var(--danger); }
.finance-item.balance .finance-value { color: var(--brand-mid); }

/* ── History timeline ───────────────────────────────────────── */
.timeline { padding: var(--sp-4); display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: var(--sp-3); position: relative; padding-bottom: var(--sp-4); }
.timeline-item::before { content: ''; position: absolute; left: 15px; top: 28px; bottom: 0; width: 2px; background: var(--border); }
.timeline-item:last-child::before { display: none; }
.timeline-dot { width: 32px; height: 32px; border-radius: var(--r-full); background: var(--surface-2); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: .8rem; }
.timeline-dot.status  { background: var(--info-light); border-color: var(--info); }
.timeline-dot.comment { background: var(--accent-light); border-color: var(--accent); }
.timeline-dot.file    { background: var(--success-light); border-color: var(--success); }
.timeline-dot.notif   { background: #F5F3FF; border-color: var(--status-waiting-parts); }
.timeline-body { flex: 1; }
.timeline-content { font-size: .875rem; }
.timeline-time { font-size: .72rem; color: var(--text-3); margin-top: 2px; }

/* ── Modal / Drawer ─────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 200; display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none; transition: opacity var(--t-mid);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%; max-height: 92dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform var(--t-mid);
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 12px auto 0; }
.modal-header { padding: var(--sp-4); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-body { padding: var(--sp-4); }
.modal-footer { padding: var(--sp-4); border-top: 1px solid var(--border); display: flex; gap: var(--sp-3); }

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container { position: fixed; top: calc(var(--navbar-h) + 8px); left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: var(--sp-2); min-width: 280px; max-width: calc(100vw - 32px); }
.toast { padding: 12px 16px; border-radius: var(--r-md); font-size: .875rem; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: var(--sp-2); animation: slideDown .25s ease; }
.toast.success { background: var(--success); color: #fff; }
.toast.error   { background: var(--danger);  color: #fff; }
.toast.info    { background: var(--brand-mid);color: #fff; }
@keyframes slideDown { from { opacity:0; transform: translateY(-12px); } to { opacity:1; transform: translateY(0); } }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state { padding: var(--sp-10) var(--sp-4); text-align: center; color: var(--text-2); }
.empty-state-icon { font-size: 3rem; margin-bottom: var(--sp-3); opacity: .4; }
.empty-state h3 { font-size: 1rem; color: var(--text); margin-bottom: var(--sp-2); }
.empty-state p { font-size: .875rem; }

/* ── Loading ────────────────────────────────────────────────── */
.spinner { width: 24px; height: 24px; border: 2.5px solid var(--border); border-top-color: var(--brand-mid); border-radius: 50%; animation: spin .7s linear infinite; }
.loading-overlay { position: absolute; inset: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; z-index: 10; }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { padding: var(--sp-3) var(--sp-4); font-size: .875rem; font-weight: 600; color: var(--text-2); border-bottom: 2.5px solid transparent; margin-bottom: -2px; white-space: nowrap; transition: color var(--t-fast), border-color var(--t-fast); }
.tab-btn.active { color: var(--brand-mid); border-bottom-color: var(--brand-mid); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Checklist ──────────────────────────────────────────────── */
.checklist-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--success); flex-shrink: 0; cursor: pointer; }
.checklist-item label { flex: 1; cursor: pointer; }
.checklist-item label.done { text-decoration: line-through; color: var(--text-3); }

/* ── Photo grid ─────────────────────────────────────────────── */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.photo-thumb { aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); cursor: pointer; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ── Misc utilities ─────────────────────────────────────────── */
.flex   { display: flex; }
.flex-1 { flex: 1; }
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.p-4   { padding: var(--sp-4); }
.px-4  { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.py-3  { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
.mt-3  { margin-top: var(--sp-3); }
.mt-4  { margin-top: var(--sp-4); }
.mb-3  { margin-bottom: var(--sp-3); }
.mb-4  { margin-bottom: var(--sp-4); }
.hidden { display: none !important; }
.w-full { width: 100%; }
.rounded { border-radius: var(--r-md); }
.border-top { border-top: 1px solid var(--border); }
.divider { height: 1px; background: var(--border); margin: var(--sp-4) 0; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* ── Desktop layout (≥ 768px) ──────────────────────────────── */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .fab { bottom: 24px; right: 24px; }
  .main-content { padding-bottom: 0; }

  /* Sidebar navigation */
  .sidebar {
    position: fixed; left: 0; top: var(--navbar-h); bottom: 0;
    width: var(--sidebar-w); background: var(--surface);
    border-right: 1px solid var(--border); overflow-y: auto;
    padding: var(--sp-3) 0; z-index: 50;
  }
  .main-content.with-sidebar { margin-left: var(--sidebar-w); }
  .sidebar-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); font-size: .9rem; font-weight: 500;
    color: var(--text-2); border-radius: var(--r-md); margin: 0 var(--sp-2);
    transition: background var(--t-fast), color var(--t-fast);
  }
  .sidebar-item:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-item.active { background: var(--brand-light); color: var(--brand-mid); font-weight: 600; }
  .sidebar-item .icon { width: 20px; height: 20px; flex-shrink: 0; }

  /* Wide modal */
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--r-xl); max-width: 600px; margin: auto; transform: translateY(20px) scale(.97); max-height: 90dvh; }
  .modal-backdrop.open .modal { transform: translateY(0) scale(1); }
  .modal-handle { display: none; }

  /* Stats grid 4 cols */
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
