:root {
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-light: #eff6ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* Header & Navigation */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.nav-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  color: #ffffff;
  font-weight: 800;
  font-size: 16px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(30, 64, 175, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.15s ease;
}
.nav-link:hover {
  color: var(--text);
  background: #f1f5f9;
  text-decoration: none;
}
.nav-link.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

.user-action {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.role-tag {
  font-size: 10px !important;
  padding: 1px 6px !important;
}

/* Main Layout */
.app-main {
  flex: 1;
  padding-top: 28px;
  padding-bottom: 40px;
}

.backline {
  margin-bottom: 20px;
}
.backline a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}
.backline a:hover {
  color: var(--text);
}

.welcome-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 4px;
}

h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

h3 {
  font-size: 16px;
  font-weight: 600;
}

.muted-text {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}
.stat-icon.purple { background: #f3e8ff; color: #7e22ce; }
.stat-icon.amber { background: #fef3c7; color: #b45309; }
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green { background: #dcfce7; color: #15803d; }

.stat-card span {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-card strong {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin: 4px 0;
}

.stat-card small {
  font-size: 12px;
  color: var(--text-muted);
}

/* Panels & Tables */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 24px;
}

.section-heading {
  margin-bottom: 16px;
}
.section-heading p {
  color: var(--text-muted);
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

th {
  padding: 12px 14px;
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: #1e40af;
  background: #eff6ff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.subline {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.empty {
  text-align: center;
  padding: 36px 14px;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 9999px;
  line-height: 1;
}

.badge.amber { background: #fef3c7; color: #92400e; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.muted { background: #f1f5f9; color: #475569; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn.primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn.primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.btn.light {
  background: #f8fafc;
  color: var(--text);
  border-color: var(--border);
}
.btn.light:hover {
  background: #f1f5f9;
  text-decoration: none;
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn.full {
  width: 100%;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 20px;
}
.alert.danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}
.alert.success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

/* Forms */
.form-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.required {
  color: #dc2626;
}
.optional {
  font-weight: 400;
  color: var(--text-muted);
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  align-items: center;
}

.form-aside {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  height: fit-content;
}

.aside-icon {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 8px;
}

.form-aside ul {
  padding-left: 20px;
  margin: 12px 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.form-aside li {
  margin-bottom: 6px;
}

.status-mini {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
}
.status-mini b {
  display: block;
  margin-bottom: 8px;
}
.status-mini div {
  padding: 4px 0;
  color: var(--text-muted);
}

/* Detail & History */
.detail-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
  margin-bottom: 24px;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.detail-fields small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-fields b {
  font-size: 15px;
}

.detail-fields .wide {
  grid-column: span 2;
}

.report-photo {
  max-width: 100%;
  max-height: 350px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.history-item {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child {
  border-bottom: none;
}

.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 6px;
}

/* Login Page */
.login-page {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-wrap {
  width: 100%;
  max-width: 440px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  margin-bottom: 24px;
}
.login-brand .brand-mark {
  background: #ffffff;
  color: #1e3a8a;
  box-shadow: none;
}
.login-brand small {
  display: block;
  opacity: 0.8;
  font-size: 12px;
}

.login-card {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.demo-box {
  margin-top: 24px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px dashed var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.demo-box b {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
}

.login-foot {
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  margin-top: 20px;
}

/* PWA Page & Cards */
.pwa-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.pwa-card {
  padding: 24px;
}
.pwa-icon {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 12px;
}

.info-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  color: #1e40af;
  font-size: 14px;
}
.info-symbol {
  font-weight: 800;
  background: #3b82f6;
  color: #ffffff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

/* Footer */
.app-footer {
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 18px 0;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: auto;
}

.foot-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.foot-links {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}
.text-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #166534;
  font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
  .nav-container {
    flex-wrap: wrap;
  }
  .nav-menu {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-top: 8px;
  }
  .form-layout, .detail-grid, .pwa-grid {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .detail-fields {
    grid-template-columns: 1fr;
  }
  .detail-fields .wide {
    grid-column: span 1;
  }
}
