/* CK Building Analytics — Design System
   Extends the DJI Route Planner dark theme */

@import url('/static/fonts/fonts.css');

:root {
  --bg-primary: #0b0f13;
  --bg-secondary: #131a24;
  --bg-tertiary: #1c2636;
  --bg-hover: #243044;
  --bg-input: #0e1318;
  --text-primary: #e4eaf2;
  --text-secondary: #8494a7;
  --text-muted: #4d5f73;
  --accent: #00b4d8;
  --accent-hover: #00d0fa;
  --accent-dim: rgba(0,180,216,0.1);
  --accent-glow: rgba(0,180,216,0.25);
  --success: #2ec4b6;
  --success-dim: rgba(46,196,182,0.12);
  --warning: #f4a261;
  --warning-dim: rgba(244,162,97,0.12);
  --danger: #e76f51;
  --danger-dim: rgba(231,111,81,0.12);
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.1);
  --thermal: #ff6b35;
  --radius: 8px;
  --radius-sm: 5px;
  --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === LAYOUT === */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--thermal));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.sidebar-brand .brand-text small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 8px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-link .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.sidebar-user .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-user .user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user .user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px;
  max-width: 1200px;
}

/* === PAGE HEADER === */
.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.page-header .breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.page-header .breadcrumb a {
  color: var(--text-secondary);
}

/* === CARDS === */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2, .card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

/* === STAT CARDS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card .stat-value.accent { color: var(--accent); }
.stat-card .stat-value.success { color: var(--success); }
.stat-card .stat-value.warning { color: var(--warning); }
.stat-card .stat-value.thermal { color: var(--thermal); }

/* === TABLES === */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tbody tr:hover {
  background: var(--bg-tertiary);
}

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

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-accent { background: var(--accent-dim); color: var(--accent); }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }
.badge-muted { background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* === FORMS === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group label .required {
  color: var(--danger);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238494a7' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

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

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

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.1); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-tertiary);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 6px 8px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* === SEARCH BAR === */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.search-bar input[type="search"] {
  flex: 1;
  max-width: 360px;
}

/* === SEARCH DROPDOWN (building form autocomplete) === */
.search-dropdown {
  display: none;
  position: absolute;
  left: 0; right: 0;
  top: 100%;
  z-index: 1000;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.search-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-hover); }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* === PAGINATION === */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
}

.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination a:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.pagination .active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* === ALERTS === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(231,111,81,0.2);
}

.alert-success {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(46,196,182,0.2);
}

.alert-warning {
  background: var(--warning-dim);
  color: var(--warning);
  border: 1px solid rgba(244,162,97,0.2);
}

/* === TOAST === */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
  max-width: 400px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === LOGIN PAGE === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.login-card .login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-card .login-brand .brand-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--accent), var(--thermal));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
}

.login-card .login-brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-card .login-brand p {
  font-size: 13px;
  color: var(--text-muted);
}

.login-card .btn-primary {
  width: 100%;
  padding: 11px;
  margin-top: 8px;
}

/* === DETAIL PAGE === */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.detail-header .meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-field {
  padding: 8px 0;
}

.detail-field .field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.detail-field .field-value {
  font-size: 14px;
  color: var(--text-primary);
}

.detail-field .field-value.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* === MAP === */
.mini-map {
  height: 200px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

/* === UTILITIES === */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-mono { font-family: var(--font-mono); }
.hidden { display: none; }

/* === RESPONSIVE === */
/* === DRAG-AND-DROP UPLOAD === */
.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}

/* === PHOTO GRID === */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px;
}
.photo-card { border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-tertiary); }
.photo-thumb {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  cursor: pointer;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.2s; }
.photo-thumb:hover img { transform: scale(1.05); }
.photo-type-badge { position: absolute; top: 6px; right: 6px; font-size: 0.65rem; }
.photo-meta { padding: 8px; }

/* === LIGHTBOX === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-content { position: relative; max-width: 95vw; max-height: 95vh; }
.lightbox-content img { max-width: 95vw; max-height: 85vh; object-fit: contain; border-radius: var(--radius); }
.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
}
.lightbox-info { text-align: center; margin-top: 12px; color: var(--text-primary); }

/* === SELECTABLE PHOTOS (report builder) === */
.selectable-photo { position: relative; cursor: pointer; }
.selectable-photo .photo-check {
  position: absolute; top: 6px; left: 6px;
  width: 24px; height: 24px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: transparent; transition: all 0.15s;
  background: rgba(0,0,0,0.3);
}
.selectable-photo.selected .photo-check {
  background: var(--accent); border-color: var(--accent); color: white;
}
.selectable-photo.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

/* === CALENDAR === */
.calendar-grid { width: 100%; border-collapse: collapse; }
.calendar-grid th { padding: 8px 4px; text-align: center; color: var(--text-muted); font-size: 0.75rem; font-weight: 500; }
.cal-cell { border: 1px solid var(--border); vertical-align: top; padding: 4px; min-height: 80px; height: 80px; }
.cal-cell.empty { background: var(--bg-primary); border-color: transparent; }
.cal-cell.today { background: var(--accent-dim); }
.cal-day { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
.cal-event { font-size: 0.65rem; padding: 2px 4px; border-radius: 3px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event.scheduled { background: var(--accent-dim); color: var(--accent); }
.cal-event.planned { background: var(--warning-dim); color: var(--warning); }
.cal-event.complete { background: var(--success-dim); color: var(--success); }
.cal-event.in_progress, .cal-event.processing, .cal-event.photos_uploaded { background: var(--accent-dim); color: var(--accent); }
.cal-event.failed { background: var(--danger-dim); color: var(--danger); }
.text-danger { color: var(--danger) !important; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
