:root {
  --bg: #F5F3EE;
  --panel: #FFFFFF;
  --border: #E4E0D6;
  --text: #1A1D21;
  --text-secondary: #6B7280;
  --text-faint: #9CA3AF;
  --accent: #F5B800;
  --accent-dark: #C99400;
  --accent-ink: #3A2B00;
  --danger: #DC2626;
  --danger-bg: #FEF0EF;
  --warn: #F59E0B;
  --warn-bg: #FEF7E8;
  --safe: #16A34A;
  --safe-bg: #EFF9F1;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  padding-bottom: 96px;
  position: relative;
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.logo-mark {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark svg { width: 26px; height: 26px; }

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.5px;
  color: var(--text);
}

.header-logout {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  opacity: 0.8;
}
.header-logout:hover {
  background: var(--danger-bg);
  opacity: 1;
}

.status-dot {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--safe);
  font-weight: 600;
}
.status-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--safe);
  box-shadow: 0 0 0 3px var(--safe-bg);
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 13px 0 11px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-faint);
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* Sub-nav / Filters */
.subnav {
  display: flex;
  gap: 10px;
  padding: 16px 20px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }

.pill-btn {
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--panel);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn.primary, .pill-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Form Groups & Fields */
form { padding: 8px 20px 20px; }
.content-pad { padding: 8px 20px 20px; } /* for lists outside forms */

.group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 16px 4px;
  margin-top: 16px;
}

.group-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.field { margin-bottom: 16px; }

.field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 7px;
  display: block;
}
.field-label .req { color: var(--danger); }

.input, select, textarea {
  width: 100%;
  background: #FBFAF7;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 14.5px;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, select:focus, textarea:focus {
  border-color: var(--accent-dark);
  background: #fff;
}
::placeholder { color: var(--text-faint); }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%236B7280' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.datetime {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1A1D21;
  color: #F5F3EE;
  border-radius: 9px;
  padding: 13px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13.5px;
  letter-spacing: 0.3px;
}
.datetime .clock-icon { font-size: 14px; opacity: 0.75; }
.datetime .sep { color: #555; margin: 0 2px; }

textarea { min-height: 90px; resize: vertical; font-family: 'IBM Plex Sans', sans-serif; }

/* Photos */
.photo-zone {
  border: 1.5px dashed var(--border);
  border-radius: 9px;
  padding: 18px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  background: #FBFAF7;
  cursor: pointer;
  transition: background 0.2s;
}
.photo-zone:hover { background: var(--border); }
.photo-zone .icon { font-size: 20px; display: block; margin-bottom: 6px; opacity: 0.5; }

.photo-previews {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.photo-thumb {
  width: 56px; height: 56px;
  border-radius: 7px;
  background: linear-gradient(135deg, #d8d3c4, #c4bfae);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #6b6656; font-weight: 700;
  border: 1px solid var(--border);
  overflow: hidden;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .remove {
  position: absolute; top: -5px; right: -5px;
  width: 17px; height: 17px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  cursor: pointer;
}

.file-input-wrapper { position: relative; overflow: hidden; display: inline-block; width: 100%; }
.file-input-wrapper input[type=file] { font-size: 100px; position: absolute; left: 0; top: 0; opacity: 0; cursor: pointer; height: 100%; }

/* Urgency pills */
.urgency-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
}
.urgency-pill {
  padding: 12px 2px;
  border-radius: 9px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  border: 1.5px solid var(--border);
  background: #FBFAF7;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.urgency-pill .dot { width: 8px; height: 8px; border-radius: 50%; }

.urgency-pill.low .dot { background: var(--safe); }
.urgency-pill.med .dot { background: var(--accent); }
.urgency-pill.high .dot { background: var(--warn); }
.urgency-pill.crit .dot { background: var(--danger); }

.urgency-pill.selected.crit { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.urgency-pill.selected.high { background: var(--warn-bg); border-color: var(--warn); color: #92620A; }
.urgency-pill.selected.med { background: #FEF9EB; border-color: var(--accent); color: var(--accent-ink); }
.urgency-pill.selected.low { background: var(--safe-bg); border-color: var(--safe); color: var(--safe); }

/* Sticky submit & Big Buttons */
.sticky-submit {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 22px 20px 18px;
  z-index: 10;
}
.submit-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 11px;
  padding: 16px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 184, 0, 0.35);
  font-family: 'IBM Plex Sans', sans-serif;
}
.submit-btn:disabled { background: var(--border); color: var(--text-faint); cursor: not-allowed; box-shadow: none; }
.submit-btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 2px 8px rgba(245, 184, 0, 0.25); }

.ghost-btn {
  width: 100%; padding: 13px; margin-top: 10px; border: 1.5px solid var(--border); border-radius: 11px; 
  background: none; color: var(--text-secondary); font-family: 'IBM Plex Sans'; font-weight: 600; font-size: 13px; letter-spacing: 0.5px; cursor: pointer;
}

/* Stubs (Tickets) */
.stub {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.stub::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
}
.stub[data-urgency="Low"]::before { background: var(--safe); }
.stub[data-urgency="Medium"]::before { background: var(--accent); }
.stub[data-urgency="High"]::before { background: var(--warn); }
.stub[data-urgency="Critical"]::before { background: var(--danger); }

.stub-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stub-id { font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.stub-machine { font-family: 'IBM Plex Mono'; font-size: 17px; font-weight: 600; margin: 4px 0; color: var(--text); }
.stub-dept { font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-bottom: 6px; }
.stub-desc { font-size: 13.5px; color: var(--text-secondary); line-height: 1.5; margin: 6px 0 10px; }
.stub-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--text-faint); font-weight: 500; }
.stub-divider { border-top: 1px dashed var(--border); margin: 12px 0; }

.stamp {
  font-size: 10px; font-weight: 700; letter-spacing: 0.8px; padding: 4px 10px; border-radius: 20px; 
  display: inline-block; white-space: nowrap; flex-shrink: 0; text-transform: uppercase;
}
.stamp.Open { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(220,38,38,0.2); }
.stamp.Acknowledged { background: #EEF4FF; color: #2563EB; border: 1px solid rgba(37,99,235,0.2); }
.stamp.In-Progress { background: var(--warn-bg); color: #B45309; border: 1px solid rgba(245,158,11,0.2); }
.stamp.Resolved { background: var(--safe-bg); color: var(--safe); border: 1px solid rgba(22,163,74,0.2); }
.stamp.Closed { background: #F3F4F6; color: #4B5563; border: 1px solid rgba(156,163,175,0.2); }

/* Photo Gallery */
.photo-gallery { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.photo-gallery img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; cursor: pointer; border: 1px solid var(--border); }

/* Utility Classes */
.hidden { display: none !important; }
.loading { text-align: center; padding: 60px 20px; color: var(--text-faint); font-size: 13px; font-weight: 500;}

.empty { text-align: center; padding: 50px 20px; color: var(--text-faint); }
.empty b { display: block; color: var(--text); font-family: 'IBM Plex Sans'; font-weight: 600; font-size: 15px; margin-bottom: 6px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1A1D21; border: 1px solid #333; color: #F5F3EE; padding: 10px 20px; border-radius: 20px; font-size: 13px; font-weight: 600; z-index: 200; box-shadow: 0 4px 20px rgba(0,0,0,0.15); white-space: nowrap; }
.toast.success { background: var(--safe); color: #fff; border-color: var(--safe); }
.toast.error { background: var(--danger); border-color: var(--danger); color: #fff; }

.confirm { text-align: center; padding: 36px 10px; }
.confirm .tick { width: 60px; height: 60px; background: var(--safe-bg); border: 2px solid var(--safe); color: var(--safe); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 0 auto 16px; }
.confirm h2 { margin: 0 0 6px; font-size: 20px; color: var(--text); }
.confirm p { color: var(--text-secondary); font-size: 14px; line-height: 1.5; }

/* Modal / Overlay */
.overlay { position: fixed; inset: 0; background: rgba(26,29,33,0.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.sheet { background: var(--bg); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 20px 20px 30px; max-height: 90vh; overflow-y: auto; animation: slideUp 0.25s ease; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
.sheet-handle { width: 40px; height: 4px; background: var(--text-faint); border-radius: 2px; margin: 0 auto 16px; opacity: 0.5; }
.sheet-close { float: right; background: none; border: none; color: var(--text-faint); font-size: 22px; cursor: pointer; line-height: 1; padding: 0 0 4px 8px; }

/* Notes / Updates */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.status-btn { padding: 11px; border-radius: 9px; border: 1.5px solid var(--border); background: var(--panel); color: var(--text-secondary); font-family: 'IBM Plex Sans'; font-weight: 600; font-size: 13px; letter-spacing: 0.3px; cursor: pointer; transition: all 0.15s; }
.status-btn.sel { background: #FEF9EB; color: var(--accent-ink); border-color: var(--accent); }

.notes-list { margin: 10px 0 0; padding: 0; list-style: none; }
.notes-list li { padding: 12px 0; border-top: 1px solid var(--border); font-size: 13.5px; line-height: 1.5; color: var(--text); }
.notes-list .n-meta { color: var(--text-faint); font-size: 11px; margin-bottom: 4px; font-family: 'IBM Plex Mono'; font-weight: 500;}

/* Stats & Reports */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 6px; text-align: center; }
.stat-card.critical-card { border-color: var(--danger); background: var(--danger-bg); }
.stat-num { font-family: 'IBM Plex Sans'; font-weight: 700; font-size: 24px; color: var(--text); margin-bottom: 2px;}
.stat-card.critical-card .stat-num { color: var(--danger); }
.stat-label { font-size: 9.5px; color: var(--text-faint); letter-spacing: 0.5px; font-family: 'IBM Plex Sans'; text-transform: uppercase; font-weight: 700; }

.refresh-hint { font-size: 11px; color: var(--text-faint); text-align: right; margin-bottom: 10px; font-weight: 500;}

.report-block { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.report-block h3 { margin: 0 0 14px; font-size: 12px; letter-spacing: 0.5px; color: var(--text-faint); font-family: 'IBM Plex Sans'; font-weight: 700; text-transform: uppercase; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 120px; font-size: 12.5px; color: var(--text-secondary); flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bar-track { flex: 1; height: 14px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar-val { width: 28px; font-size: 12.5px; color: var(--text); text-align: right; flex-shrink: 0; font-family: 'IBM Plex Mono'; font-weight: 500;}

/* Drawer */
.drawer-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: 0.3s; z-index: 999;
}
.drawer-overlay.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; right: -280px; width: 280px; height: 100%;
  background: var(--panel); box-shadow: -4px 0 16px rgba(0,0,0,0.1);
  transition: 0.3s; z-index: 1000; display: flex; flex-direction: column;
}
.drawer.open { right: 0; }
.drawer-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.drawer-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary); padding: 0; line-height: 1; }
.drawer-links { padding: 20px; display: flex; flex-direction: column; gap: 15px; flex: 1; }
.drawer-links a { text-decoration: none; color: var(--text); font-weight: 500; font-size: 15px; }
.drawer-links a:hover { color: var(--accent-dark); }
.drawer-footer { padding: 20px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); text-align: center; }
.hamburger { background: none; border: none; cursor: pointer; color: var(--text); display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin-right: -10px;}