/* ── TORSAL ERP Mobile App ── */
:root {
  --c-bg: #f5f5f7;
  --c-card: #ffffff;
  --c-card-hover: #f0f0f2;
  --c-border: #e0e0e4;
  --c-text: #1a1a1e;
  --c-muted: #6b6b76;
  --c-subtle: #50505a;
  --c-accent: #2563eb;
  --c-accent-l: rgba(37,99,235,.08);
  --c-green: #16a34a;
  --c-red: #dc2626;
  --c-amber: #d97706;
  --c-purple: #9333ea;
  --c-teal: #0d9488;
  --c-blue: #2563eb;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --r: 12px;
  --r-sm: 8px;
  --topbar-h: 56px;
  --bottomnav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Prevent iOS zoom on input focus */
input, select, textarea { font-size: 16px !important; font-family: var(--font); }

/* ── APP CONTAINER ── */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── SCREENS ── */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
}
.screen.active { display: flex; flex-direction: column; }

/* ── TOP BAR ── */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo {
  width: 32px; height: 32px;
  background: var(--c-accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: #fff;
}
.topbar-info { display: flex; flex-direction: column; }
.topbar-name { font-weight: 600; font-size: 14px; }
.topbar-date { font-size: 11px; color: var(--c-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-btn {
  width: 36px; height: 36px;
  border: none; background: transparent;
  color: var(--c-subtle); font-size: 18px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.topbar-btn:active { background: var(--c-border); }
.notif-badge {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px;
  background: var(--c-red); border-radius: 50%;
  font-size: 9px; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.notif-badge:empty { display: none; }

/* ── BOTTOM NAVIGATION ── */
.bottom-nav {
  display: flex;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  padding-bottom: var(--safe-bottom);
  min-height: var(--bottomnav-h);
  z-index: 100;
}
.nav-tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  padding: 8px 0;
  border: none; background: transparent;
  color: var(--c-muted); font-size: 10px;
  cursor: pointer; text-decoration: none;
  font-family: var(--font);
}
.nav-tab .nav-icon { font-size: 20px; }
.nav-tab.active { color: var(--c-accent); }
.nav-tab:active { background: var(--c-accent-l); }

/* ── TILES GRID ── */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}
.tile {
  min-height: 88px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px;
  border-radius: var(--r);
  background: var(--c-card);
  border: 1px solid var(--c-border);
  cursor: pointer;
  transition: transform .1s;
  padding: 12px 8px;
}
.tile:active { transform: scale(0.96); background: var(--c-card-hover); }
.tile-icon { font-size: 28px; }
.tile-label { font-size: 12px; font-weight: 600; text-align: center; }
.tile-accent { border-left: 3px solid; }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--c-accent);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.fab:active { transform: scale(0.9); }

/* ── CARDS ── */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 14px 16px;
  margin: 0 16px 12px;
}
.card-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.card-subtitle { font-size: 11px; color: var(--c-muted); margin-bottom: 4px; }
.card-value { font-size: 14px; font-weight: 500; }
.card-row {
  display: flex; justify-content: space-between;
  align-items: center; padding: 8px 0;
  border-bottom: 1px solid var(--c-border);
}
.card-row:last-child { border-bottom: none; }

/* ── SECTION HEADERS ── */
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px 8px;
}
.section-title { font-size: 13px; font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .5px; }
.section-link { font-size: 12px; color: var(--c-accent); cursor: pointer; border: none; background: none; font-family: var(--font); }

/* ── SCHEDULE ENTRIES ── */
.sched-item {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 14px 16px;
  margin: 0 16px 10px;
  cursor: pointer;
  position: relative;
}
.sched-item:active { background: var(--c-card-hover); }
.sched-time { font-size: 13px; font-weight: 700; color: var(--c-accent); margin-bottom: 4px; }
.sched-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.sched-client { font-size: 12px; color: var(--c-subtle); margin-bottom: 6px; }
.sched-address { font-size: 12px; color: var(--c-muted); }
.sched-type {
  display: inline-block;
  padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase;
}
.sched-type.montaz { background: rgba(37,99,235,.15); color: var(--c-accent); }
.sched-type.serwis { background: rgba(34,197,94,.15); color: var(--c-green); }
.sched-type.pomiar { background: rgba(168,85,247,.15); color: var(--c-purple); }
.sched-type.reklamacja { background: rgba(239,68,68,.15); color: var(--c-red); }
.sched-alert {
  position: absolute; top: 10px; right: 12px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.sched-workers { font-size: 11px; color: var(--c-muted); margin-top: 4px; }
.sched-actions {
  display: flex; gap: 8px; margin-top: 10px;
  border-top: 1px solid var(--c-border); padding-top: 10px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 20px;
  border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600;
  border: none; cursor: pointer;
  font-family: var(--font);
  transition: transform .1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-secondary { background: var(--c-card-hover); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-danger { background: var(--c-red); color: #fff; }
.btn-success { background: var(--c-green); color: #fff; }
.btn-accent { background: var(--c-accent); color: #fff; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-nav {
  height: 44px; padding: 0 16px;
  background: var(--c-accent); color: #fff;
  border-radius: var(--r-sm); border: none;
  font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-family: var(--font);
  flex: 1;
}
.btn-nav:active { opacity: .85; }
.btn-phone {
  height: 44px; width: 44px;
  background: var(--c-green); color: #fff;
  border-radius: var(--r-sm); border: none;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── FORMS ── */
.form-group { margin-bottom: 14px; padding: 0 16px; }
.form-label {
  display: block;
  font-size: 11px; font-weight: 600; color: var(--c-muted);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 6px;
}
.form-input {
  width: 100%; height: 48px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 0 14px;
  color: var(--c-text);
  outline: none;
}
.form-input:focus { border-color: var(--c-accent); }
.form-textarea {
  width: 100%; min-height: 100px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  color: var(--c-text);
  outline: none; resize: vertical;
}
.form-textarea:focus { border-color: var(--c-accent); }
.form-select {
  width: 100%; height: 48px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 0 14px;
  color: var(--c-text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2371717a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.form-select:focus { border-color: var(--c-accent); }

/* Priority toggle buttons */
.priority-group { display: flex; gap: 8px; padding: 0 16px; margin-bottom: 14px; }
.priority-btn {
  flex: 1; height: 44px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-bg);
  color: var(--c-muted);
  font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
}
.priority-btn.active { border-color: currentColor; }
.priority-btn.p-normal.active { color: var(--c-green); background: rgba(34,197,94,.1); }
.priority-btn.p-pilny.active { color: var(--c-amber); background: rgba(245,158,11,.1); }
.priority-btn.p-krytyczny.active { color: var(--c-red); background: rgba(239,68,68,.1); }

/* ── SCREEN HEADER (back + title) ── */
.screen-header {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); min-height: var(--topbar-h);
  padding: 0 16px;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
}
.back-btn {
  width: 36px; height: 36px;
  border: none; background: transparent;
  color: var(--c-text); font-size: 20px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.back-btn:active { background: var(--c-border); }
.screen-title { font-size: 16px; font-weight: 600; flex: 1; }
.screen-action {
  border: none; background: transparent;
  color: var(--c-accent); font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
}

/* ── STATUS BADGES ── */
.status {
  display: inline-block;
  padding: 3px 10px; border-radius: 12px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .3px;
}
.status-new { background: rgba(37,99,235,.15); color: var(--c-accent); }
.status-progress { background: rgba(245,158,11,.15); color: var(--c-amber); }
.status-done { background: rgba(34,197,94,.15); color: var(--c-green); }
.status-cancelled { background: rgba(239,68,68,.15); color: var(--c-red); }

/* ── ALERT BANNERS ── */
.alert-banner {
  margin: 8px 16px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  font-size: 12px; font-weight: 500;
  display: flex; align-items: flex-start; gap: 8px;
}
.alert-danger { background: rgba(239,68,68,.12); color: var(--c-red); border: 1px solid rgba(239,68,68,.25); }
.alert-warning { background: rgba(245,158,11,.12); color: var(--c-amber); border: 1px solid rgba(245,158,11,.25); }
.alert-info { background: rgba(37,99,235,.12); color: var(--c-accent); border: 1px solid rgba(37,99,235,.25); }

/* ── MEDIA UPLOAD ── */
.media-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; padding: 0 16px; margin-bottom: 14px;
}
.media-thumb {
  aspect-ratio: 1; border-radius: var(--r-sm);
  overflow: hidden; position: relative;
  background: var(--c-bg); border: 1px solid var(--c-border);
}
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,.7); border-radius: 50%;
  color: #fff; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
}
.media-add {
  aspect-ratio: 1;
  border: 2px dashed var(--c-border);
  border-radius: var(--r-sm);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; cursor: pointer;
  color: var(--c-muted); font-size: 11px;
}
.media-add .media-add-icon { font-size: 24px; }
.media-add:active { background: var(--c-card); }

/* ── TOAST ── */
.app-toast {
  position: fixed; bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  left: 16px; right: 16px;
  padding: 14px 16px;
  border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500;
  z-index: 9999;
  animation: slideUp .25s ease;
}
.app-toast.success { background: var(--c-green); color: #fff; }
.app-toast.error { background: var(--c-red); color: #fff; }
.app-toast.warning { background: var(--c-amber); color: #000; }
.app-toast.info { background: var(--c-accent); color: #fff; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── DAY NAVIGATION ── */
.day-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 12px 16px;
}
.day-nav-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--c-border);
  border-radius: 50%; background: transparent;
  color: var(--c-text); font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.day-nav-btn:active { background: var(--c-card); }
.day-nav-label { font-size: 15px; font-weight: 600; min-width: 120px; text-align: center; flex:1; }
.day-nav-today {
  font-size: 11px; color: var(--c-accent);
  cursor: pointer; border: none; background: none;
  font-family: var(--font); font-weight: 600;
}

/* ── EMPTY STATE ── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 24px;
  color: var(--c-muted); text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.empty-text { font-size: 14px; }

/* ── INSTALL BANNER ── */
.install-banner {
  display: none;
  margin: 8px 16px;
  padding: 12px 14px;
  background: var(--c-accent);
  border-radius: var(--r);
  color: #fff;
  align-items: center; gap: 12px;
}
.install-banner.show { display: flex; }
.install-text { flex: 1; font-size: 13px; font-weight: 500; }
.install-btn {
  padding: 8px 16px;
  background: #fff; color: var(--c-accent);
  border: none; border-radius: 6px;
  font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  font-family: var(--font);
}
.install-close {
  background: none; border: none;
  color: rgba(255,255,255,.7); font-size: 18px;
  cursor: pointer;
}

/* ── LANDSCAPE ADJUSTMENT ── */
@media (orientation: landscape) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .media-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ── LARGER PHONES ── */
@media (min-width: 420px) {
  .tile { min-height: 96px; }
  .tile-icon { font-size: 32px; }
  .tile-label { font-size: 13px; }
}

/* ── AUTOCOMPLETE ── */
.autocomplete-list {
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--r-sm); z-index: 50;
  max-height: 220px; overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  margin-top: 2px;
}
.autocomplete-item {
  padding: 10px 12px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--c-border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item:active { background: var(--c-card-hover); }
.form-group { position: relative; }

/* ── STATUS INLINE ── */
.status {
  display: inline-block; padding: 3px 10px;
  border-radius: 10px; font-size: 11px; font-weight: 600;
}

/* ── SCHEDULE WORKERS ── */
.sched-workers { font-size: 11px; color: var(--c-muted); }

/* ── CHAT ── */
#chatContent {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
}
#chatMessages {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.btn-ghost {
  height: 32px; padding: 0 10px;
  border: none; background: transparent;
  color: var(--c-accent); font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
}
.btn-ghost:active { opacity: .7; }

/* ── CHECKLIST PROGRESS BAR ── */
.checklist-progress {
  height: 6px; background: var(--c-border);
  border-radius: 3px; overflow: hidden; margin-top: 8px;
}
.checklist-progress-fill {
  height: 100%; border-radius: 3px;
  transition: width .3s ease;
}

/* ── PHOTO GALLERY GRID ── */
.photo-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; padding: 0 16px;
}
.photo-grid-item {
  position: relative; aspect-ratio: 1;
  border-radius: var(--r-sm); overflow: hidden;
  background: var(--c-card);
}
.photo-grid-item img, .photo-grid-item video {
  width: 100%; height: 100%; object-fit: cover;
}
.photo-badge {
  position: absolute; top: 4px; left: 4px;
  background: rgba(0,0,0,.7); color: #fff;
  font-size: 9px; padding: 2px 6px; border-radius: 4px;
}

/* ── MANAGER DASHBOARD GRID ── */
.mgr-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; padding: 0 0 12px;
}
.mgr-stat-card {
  text-align: center; padding: 14px 12px;
}
.mgr-stat-value { font-size: 22px; font-weight: 700; }
.mgr-stat-label { font-size: 10px; color: var(--c-muted); margin-top: 2px; }

/* ── TIMELINE ITEMS ── */
.timeline-item {
  border-left: 3px solid var(--c-border);
  padding: 8px 14px; margin-bottom: 6px;
  background: var(--c-card); border-radius: var(--r-sm);
}
.timeline-item-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
}
.timeline-item-body { font-size: 12px; }
.timeline-item-meta { font-size: 10px; color: var(--c-muted); margin-top: 2px; }

/* ── OFFLINE INDICATOR ── */
.offline-banner {
  position: fixed; top: var(--topbar-h); left: 0; right: 0;
  background: var(--c-amber); color: #000;
  text-align: center; padding: 4px 12px;
  font-size: 11px; font-weight: 600;
  z-index: 200; display: none;
}
.offline-banner.show { display: block; }

/* ── LOADING SPINNER ── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LANDSCAPE / TABLET ── */
@media (min-width: 600px) {
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
  .mgr-stats { grid-template-columns: repeat(4, 1fr); }
}

/* ══ DARK THEME ══ */
[data-theme="dark"] {
  --c-bg: #0e0f11;
  --c-card: #16171b;
  --c-card-hover: #1c1d22;
  --c-border: #25262b;
  --c-text: #e4e4e7;
  --c-muted: #71717a;
  --c-subtle: #a1a1aa;
  --c-accent: #2563eb;
  --c-accent-l: rgba(37,99,235,.12);
  --c-green: #22c55e;
  --c-red: #ef4444;
  --c-amber: #f59e0b;
  --c-purple: #a855f7;
  --c-teal: #14b8a6;
  --c-blue: #3b82f6;
}
[data-theme="dark"] .autocomplete-list {
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
[data-theme="dark"] .media-thumb .remove {
  background: rgba(0,0,0,.7);
}

/* ── THEME TOGGLE ── */
.theme-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--c-card); border: 1px solid var(--c-border);
  border-radius: var(--r); margin: 12px 16px 0;
}
.theme-toggle-label { font-size: 13px; font-weight: 500; }
.theme-switch {
  position: relative; width: 48px; height: 28px; cursor: pointer;
}
.theme-switch input { opacity: 0; width: 0; height: 0; }
.theme-slider {
  position: absolute; inset: 0;
  background: var(--c-border); border-radius: 14px;
  transition: background .2s;
}
.theme-slider::before {
  content: '';
  position: absolute; left: 3px; top: 3px;
  width: 22px; height: 22px;
  background: var(--c-text); border-radius: 50%;
  transition: transform .2s;
}
.theme-switch input:checked + .theme-slider { background: var(--c-accent); }
.theme-switch input:checked + .theme-slider::before { transform: translateX(20px); background: #fff; }
