/* ============================================================
   TAP-Core V6.0 — 메인 스타일시트
   Vanilla CSS (React/Vue/Tailwind 사용 금지 — Golden Rules)
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #34a853;
  --success-light: #e6f4ea;
  --warning: #fbbc04;
  --warning-light: #fef7e0;
  --danger: #ea4335;
  --danger-light: #fce8e6;
  --info: #4285f4;
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --border: #dadce0;
  --border-light: #e8eaed;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.logo { font-size: 18px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.logo-icon { width: 28px; height: 28px; border-radius: 4px; }
.logo .version { font-size: 12px; font-weight: 400; color: var(--text-secondary); }

.header-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-link:hover { background: #f1f3f4; color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }

.header-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 14px; font-weight: 500; }
.user-role {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #d32f2f; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: var(--text-secondary); padding: 4px 8px;
}
.btn-icon:hover { color: var(--primary); }

/* --- Main Content --- */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 24px; font-weight: 600; }
.page-desc { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

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

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.stat-card:hover { box-shadow: var(--shadow-hover); }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }

.stat-materials .stat-value { color: var(--primary); }
.stat-labor .stat-value { color: var(--success); }
.stat-expenses .stat-value { color: var(--warning); }
.stat-total .stat-value { color: var(--text); }

/* --- Section Layout --- */
.section-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.section-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.section-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* --- Chart Container --- */
.chart-container {
  position: relative;
  height: 280px;
}

/* --- Content Area --- */
.content-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: 200px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 0;
  font-size: 14px;
}

/* --- List Items --- */
.list-container { min-height: 100px; }

.list-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg); }

.list-item-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.list-item-name { font-weight: 500; font-size: 14px; }
.list-item-sub {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

/* --- Budget Bar --- */
.budget-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  margin: 8px 0;
  overflow: hidden;
}
.budget-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.budget-warning { background: var(--warning); }
.budget-danger { background: var(--danger); }

.alert-warning { border-left: 3px solid var(--warning); }
.alert-danger { border-left: 3px solid var(--danger); }
.alert-error {
  background: var(--danger-light, #fce8e6);
  color: var(--danger, #d93025);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin: 8px 0;
  border-left: 3px solid var(--danger, #d93025);
}

/* --- Button variants --- */
.btn-outline {
  background: transparent;
  border: 1px solid #dadce0;
  color: var(--text-secondary, #5f6368);
}
.btn-outline:hover { background: #f1f3f4; }
.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
  line-height: 1.4;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-active { background: var(--success-light); color: var(--success); }
.badge-completed { background: var(--primary-light); color: var(--primary); }
.badge-draft { background: var(--warning-light); color: #e37400; }
.badge-archived { background: #f1f3f4; color: var(--text-secondary); }
.badge-warning { background: var(--warning-light); color: #e37400; }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-type-materials { background: var(--primary-light); color: var(--primary); }
.badge-type-labor { background: var(--success-light); color: var(--success); }
.badge-type-expenses { background: var(--warning-light); color: #e37400; }
.badge-source { background: #f1f3f4; color: var(--text-secondary); }
.badge-action { background: var(--primary-light); color: var(--primary); }
.badge-severity-info { background: var(--primary-light); color: var(--primary); }
.badge-severity-warn { background: var(--warning-light); color: #e37400; }
.badge-severity-error { background: var(--danger-light); color: var(--danger); }

/* --- Data Table --- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}
.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--bg); }
.data-table.compact td { padding: 6px 10px; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.font-bold { font-weight: 600; }
.clickable-row { cursor: pointer; }

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.toolbar-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* --- Forms --- */
.form-select, .form-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s;
}
.form-select:focus, .form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26,115,232,0.15);
}
.form-select { min-width: 180px; }
.form-select-sm {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--bg-card);
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-group .form-input,
.form-group .form-select {
  width: 100%;
}

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

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 24px; color: var(--text-secondary); padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  margin-top: 8px;
}

/* --- Invoice Detail --- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.detail-section h4 {
  font-size: 14px; font-weight: 600;
  margin-bottom: 8px; color: var(--text-secondary);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.detail-label { color: var(--text-secondary); }
.detail-totals {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.total-row { font-size: 16px; border-bottom: none; padding-top: 8px; }
.detail-notes {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.detail-notes h4 { font-size: 13px; margin-bottom: 4px; }
.detail-notes p { font-size: 13px; color: var(--text-secondary); }

/* --- Tab Bar --- */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}
.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- Health Cards --- */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.health-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.health-up { border-color: var(--success); }
.health-down { border-color: var(--danger); background: var(--danger-light); }
.health-indicator {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.indicator-up { background: var(--success); }
.indicator-down { background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.health-name { font-size: 14px; font-weight: 500; }
.health-status { font-size: 12px; color: var(--text-secondary); }
.health-latency { font-size: 11px; color: var(--text-muted); }
.health-meta { font-size: 12px; color: var(--text-muted); }

.config-value {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Tax Invoice (세금계산서 양식) --- */
.tax-invoice {
  max-width: 820px;
  margin: 0 auto;
}
.ti-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 8px;
  margin: 12px 0 2px;
  color: var(--text);
}
.ti-subtitle {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.ti-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  margin-bottom: -1px;
  font-size: 13px;
}
.ti-table td,
.ti-table th {
  border: 1px solid var(--border);
  padding: 5px 8px;
  font-size: 12px;
}
.ti-th {
  background: var(--bg);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.ti-vert {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 4px;
  text-align: center;
  background: var(--bg);
}
.ti-parties {
  display: flex;
  gap: 0;
}
.ti-party {
  flex: 1;
}
.ti-items {
  font-size: 12px;
}
.ti-items thead th {
  background: var(--bg);
  font-weight: 600;
  padding: 5px 6px;
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.ti-items tbody td {
  padding: 4px 6px;
  border: 1px solid var(--border);
}
.ti-items tfoot td {
  border: 1px solid var(--border);
  padding: 5px 6px;
}
.ti-footer-text {
  text-align: center;
  margin: 16px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.text-center { text-align: center; }

/* --- Finance Module --- */
.sync-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.sync-status-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.sync-status-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.finance-summary-bar {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.finance-summary-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.finance-summary-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 60px;
}
.finance-summary-bar-track {
  flex: 1;
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}
.finance-summary-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.finance-summary-amount {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 140px;
  text-align: right;
}
.finance-summary-total {
  text-align: right;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text);
}

/* --- Legacy iframe --- */
.legacy-embed { text-align: center; }
.legacy-iframe {
  width: 100%;
  height: calc(100vh - 180px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  transform: translateX(120%);
  transition: transform 0.3s ease;
  max-width: 360px;
}
.toast-show { transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: #e37400; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .header { flex-wrap: wrap; height: auto; padding: 12px; gap: 8px; }
  .header-nav { order: 3; width: 100%; overflow-x: auto; }
  .section-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .modal-content { width: 95%; }
}
