/* ==========================================================================
   建築圖面面積框選與分析系統 - Style System
   ========================================================================== */

:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --border-color: #334155;
  --border-focus: #3b82f6;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);

  --accent: #10b981;
  --accent-light: rgba(16, 185, 129, 0.15);

  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #cbd5e1;

  --font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* 應用程式總容器 */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* --------------------------------------------------------------------------
   頂部導覽列 / 工具列
   -------------------------------------------------------------------------- */
.app-header {
  height: 64px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.brand-text .version {
  font-size: 0.7rem;
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

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

.divider {
  width: 1px;
  height: 28px;
  background-color: var(--border-color);
  margin: 0 4px;
}

/* 按鈕樣式 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  font-family: inherit;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: #334155;
  color: var(--text-main);
  border-color: #475569;
}

.btn-secondary:hover {
  background-color: #475569;
  color: white;
}

.btn-tool {
  background-color: transparent;
  color: var(--text-sub);
  border-color: transparent;
}

.btn-tool:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: white;
}

.btn-tool.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: rgba(59, 130, 246, 0.4);
  font-weight: 600;
}

.btn-snap-active {
  background-color: rgba(16, 185, 129, 0.15) !important;
  color: #10b981 !important;
  border-color: rgba(16, 185, 129, 0.4) !important;
}

#btnAutoDetect {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  color: white;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
  font-weight: 600;
}

#btnAutoDetect:hover {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  transform: translateY(-1px);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
}

.btn-danger-ghost {
  background-color: transparent;
  color: #f87171;
}

.btn-danger-ghost:hover {
  background-color: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   主工作區 Layout
   -------------------------------------------------------------------------- */
.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* 畫布視窗 */
.canvas-workspace {
  flex: 1;
  position: relative;
  background-color: #0b0f19;
  background-image: 
    radial-gradient(#1e293b 1px, transparent 1px),
    radial-gradient(#1e293b 1px, #0b0f19 1px);
  background-size: 40px 40px;
  background-position: 0 0, 20px 20px;
  overflow: hidden;
  cursor: crosshair;
  transition: outline 0.2s;
}

.canvas-workspace.drag-over {
  outline: 4px dashed #3b82f6;
  outline-offset: -8px;
  background-color: rgba(59, 130, 246, 0.05);
}

#mainCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 浮動提示條 */
.toast-instruction {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  pointer-events: none;
  transition: all 0.3s ease;
}

.toast-instruction i {
  color: var(--primary);
  font-size: 1.1rem;
}

/* 縮放控制浮條 */
.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background-color: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  padding: 4px;
  gap: 4px;
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text-sub);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.zoom-controls button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.zoom-controls #zoomLevel {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0 8px;
  min-width: 50px;
  text-align: center;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   右側側邊欄 Sidebar
   -------------------------------------------------------------------------- */
.app-sidebar {
  width: 360px;
  background-color: var(--bg-dark);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
  z-index: 90;
}

.sidebar-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 12px 16px;
  background-color: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h3 i {
  color: var(--primary);
}

.badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 12px;
  background-color: #475569;
  color: var(--text-sub);
}

.badge.success {
  background-color: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.card-body {
  padding: 14px;
}

/* 比例尺資訊格 */
.scale-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.info-item {
  background: rgba(15, 23, 42, 0.6);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.info-item .label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.info-item .value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.scale-hint {
  display: flex;
  gap: 8px;
  font-size: 0.75rem;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.1);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 158, 11, 0.2);
  line-height: 1.4;
}

/* 總面積摘要統計塊 */
.total-stat-box {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.15));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  margin-bottom: 12px;
}

.stat-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.stat-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: #60a5fa;
  letter-spacing: -1px;
}

.stat-unit {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.stat-sub {
  font-size: 0.82rem;
  color: var(--text-sub);
  margin-top: 4px;
}

.summary-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
}

.breakdown-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.breakdown-item strong {
  color: var(--text-main);
}

/* 區域清單列表 */
.zone-list-container {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.empty-state {
  text-align: center;
  padding: 30px 10px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.88rem;
}

.empty-state small {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* 區域項目 Card */
.zone-item {
  background-color: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color 0.2s, transform 0.1s;
}

.zone-item:hover {
  border-color: var(--primary);
  transform: translateX(2px);
}

.zone-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.color-picker-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
}

.zone-details {
  display: flex;
  flex-direction: column;
}

.zone-name-input {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.88rem;
  font-family: inherit;
  width: 120px;
}

.zone-name-input:focus {
  outline: 1px solid var(--primary);
  background: var(--bg-dark);
  border-radius: 2px;
}

.zone-metrics {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.zone-metrics strong {
  color: #38bdf8;
}

.zone-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
  width: 26px;
  height: 26px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-icon.delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Modal 對話框
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
}

.modal-header h3 i {
  color: var(--primary);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.btn-close:hover {
  color: white;
}

.modal-body {
  padding: 20px;
  font-size: 0.9rem;
  color: var(--text-sub);
}

.form-group {
  margin-top: 14px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-main);
}

.input-with-unit {
  display: flex;
  gap: 8px;
}

.input-with-unit input {
  flex: 1;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
}

.input-with-unit input:focus {
  outline: none;
  border-color: var(--primary);
}

.input-with-unit select {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.modal-footer {
  padding: 14px 20px;
  background-color: rgba(15, 23, 42, 0.4);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 空間名稱自訂 Modal 專用樣式 */
.modal-zone-name {
  max-width: 480px;
}

.modal-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.quick-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag-chip {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.tag-chip:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  transform: translateY(-1px);
}

.tag-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

#zoneNameInput {
  width: 100%;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}

#zoneNameInput:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.color-palette-picker {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 0;
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 2px solid transparent;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: white;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
  transform: scale(1.15);
}

/* 滾動條客製化 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #475569;
}
