/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f8fafc;
  color: #1e293b;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.app {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: #1e293b;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid #334155;
}
.brand-icon {
  color: #3b82f6;
  flex-shrink: 0;
}
.brand-name {
  color: #f1f5f9;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 12px;
  color: #64748b;
}
.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-item:hover {
  background: #334155;
  color: #e2e8f0;
}
.nav-item.active {
  background: #2563eb;
  color: #fff;
}
.sidebar-footer {
  padding: 16px 20px;
  font-size: 12px;
  color: #475569;
  border-top: 1px solid #334155;
}

/* === Content Area === */
.content {
  flex: 1;
  overflow-y: auto;
  background: #f8fafc;
}
#app-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
}

/* === Project List === */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-title {
  font-size: 24px;
  font-weight: 700;
  color: #0f172a;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}
.project-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.project-card:hover {
  border-color: #2563eb;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}
.project-card-name {
  font-size: 17px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 4px;
}
.project-card-address {
  font-size: 14px;
  color: #64748b;
  margin-bottom: 12px;
}
.project-card-meta {
  font-size: 13px;
  color: #475569;
  margin-bottom: 16px;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.status-complete .dot { background: #22c55e; }
.status-complete { background: #f0fdf4; color: #16a34a; }
.status-analyzing .dot { background: #f59e0b; }
.status-analyzing { background: #fffbeb; color: #d97706; }
.status-ready .dot { background: #3b82f6; }
.status-ready { background: #eff6ff; color: #2563eb; }
.project-card-date {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 12px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary {
  background: #2563eb;
  color: #fff;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* === Project Detail === */
.project-header {
  margin-bottom: 24px;
}
.project-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 4px;
}
.project-detail-name {
  font-size: 26px;
  font-weight: 700;
  color: #0f172a;
}
.project-detail-meta {
  font-size: 14px;
  color: #64748b;
  margin-bottom: 20px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #64748b;
  text-decoration: none;
  margin-bottom: 16px;
}
.back-link:hover { color: #2563eb; }

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 28px;
}
.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: #1e293b; }
.tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Phase 1: Plan Analysis === */
.plan-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 28px;
}
@media (max-width: 1024px) {
  .plan-layout { grid-template-columns: 1fr; }
}

/* Plan Viewer */
.plan-viewer {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.plan-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.plan-viewer-title {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
}
.page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-nav-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: #475569;
}
.page-nav-btn:hover { background: #f1f5f9; }
.page-nav-btn:disabled { opacity: 0.4; cursor: default; }
.page-counter {
  font-size: 13px;
  color: #64748b;
  min-width: 60px;
  text-align: center;
}
.plan-viewer-body {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: #f8fafc;
}
.plan-viewer-body img {
  max-width: 100%;
  max-height: 600px;
  object-fit: contain;
  border-radius: 4px;
}
.page-tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  border-top: 1px solid #e2e8f0;
  overflow-x: auto;
}
.page-tab {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  border-top: none;
  border-left: none;
  border-right: none;
  background: none;
  transition: all 0.15s;
}
.page-tab:hover { color: #1e293b; }
.page-tab.active { color: #2563eb; border-bottom-color: #2563eb; }
.page-tab.primary { font-weight: 600; }
.page-tab.skip { color: #94a3b8; }

/* Extracted Data */
.data-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.data-section {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.data-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.data-section-header:hover { background: #f8fafc; }
.data-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}
.data-section-toggle {
  font-size: 12px;
  color: #94a3b8;
  transition: transform 0.2s;
}
.data-section.collapsed .data-section-toggle { transform: rotate(-90deg); }
.data-section-body {
  padding: 0 18px 16px;
}
.data-section.collapsed .data-section-body { display: none; }

.data-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid #f1f5f9;
}
.data-row:last-child { border-bottom: none; }
.data-label { color: #64748b; }
.data-value { color: #0f172a; font-weight: 500; text-align: right; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  color: #64748b;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #e2e8f0;
  background: #f8fafc;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
.data-table tr:hover td { background: #f8fafc; }

.note-item {
  font-size: 13px;
  color: #475569;
  padding: 4px 0;
  padding-left: 14px;
  position: relative;
}
.note-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 11px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #94a3b8;
}
.special-wall {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  font-size: 13px;
}
.special-wall-badge {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* === Phase 2: Prebuilt Guide === */
.guide-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 800px;
}
.guide-step {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.guide-step.completed {
  border-color: #bbf7d0;
}
.guide-step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.guide-step-header:hover { background: #f8fafc; }
.step-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid #d1d5db;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.step-checkbox:hover { border-color: #2563eb; }
.step-checkbox.checked {
  background: #22c55e;
  border-color: #22c55e;
}
.step-checkbox.checked::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}
.step-number {
  font-size: 13px;
  font-weight: 700;
  color: #94a3b8;
  min-width: 28px;
}
.guide-step.completed .step-number { color: #22c55e; }
.step-title {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
  flex: 1;
}
.guide-step.completed .step-title {
  color: #64748b;
  text-decoration: line-through;
}
.step-page-ref {
  font-size: 12px;
  color: #2563eb;
  background: #eff6ff;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
}
.step-toggle {
  color: #94a3b8;
  font-size: 12px;
  transition: transform 0.2s;
}
.guide-step.collapsed .step-toggle { transform: rotate(-90deg); }
.guide-step-body {
  padding: 0 20px 20px 64px;
}
.guide-step.collapsed .guide-step-body { display: none; }
.step-instructions {
  font-size: 14px;
  color: #334155;
  line-height: 1.7;
  white-space: pre-line;
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
  margin-top: 24px;
  background: #fff;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: #2563eb;
  background: #eff6ff;
}
.upload-zone-icon {
  font-size: 36px;
  margin-bottom: 12px;
  color: #94a3b8;
}
.upload-zone-text {
  font-size: 15px;
  font-weight: 500;
  color: #475569;
  margin-bottom: 4px;
}
.upload-zone-sub {
  font-size: 13px;
  color: #94a3b8;
}
.upload-zone input[type="file"] { display: none; }

/* === Phase 3: Delivery Packages === */
.packages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.packages-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.package-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.package-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid #e2e8f0;
  cursor: pointer;
}
.package-card-header:hover { background: #f8fafc; }
.package-icon {
  font-size: 20px;
  margin-right: 12px;
}
.package-title {
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
}
.package-desc {
  font-size: 13px;
  color: #64748b;
  margin-top: 2px;
}
.package-when {
  font-size: 12px;
  color: #2563eb;
  background: #eff6ff;
  padding: 3px 10px;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
}
.package-item-count {
  font-size: 13px;
  color: #94a3b8;
  margin-left: 12px;
}
.package-card-body {
  padding: 0;
}
.package-card.collapsed .package-card-body { display: none; }
.package-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.package-table th {
  text-align: left;
  padding: 10px 22px;
  color: #64748b;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.package-table td {
  padding: 10px 22px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
.package-table tr:last-child td { border-bottom: none; }
.package-table tr:hover td { background: #fafbfc; }
.package-card-footer {
  padding: 14px 22px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Sanity Check */
.sanity-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 22px;
  margin-top: 24px;
}
.sanity-title {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sanity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  color: #334155;
}
.sanity-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* === New Project Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 20px;
}
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar { width: 64px; min-width: 64px; }
  .brand-name, .brand-sub, .nav-item span, .sidebar-footer { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px; }
  .nav-item { justify-content: center; padding: 12px; }
  #app-content { padding: 20px; }
  .page-tabs { padding: 0 8px; }
}
