/* === 房源預訂管理系統 - 現代化設計風格 === */

:root {
  /* 顏色系統 - 與範例圖片一致 */
  --bg-gray: #f5f5f5;
  --white: #ffffff;
  --border-gray: #e0e0e0;
  --text-dark: #2c2c2c;
  --text-gray: #666666;
  --text-light: #999999;
  --blue-primary: #4a90e2;
  --blue-hover: #357abd;
  --green-success: #22c55e;
  --red-danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "微軟正黑體", sans-serif;
  background: var(--bg-gray);
  color: var(--text-dark);
  font-size: 14px;
  line-height: 1.5;
}

a {
  text-decoration: none;
  color: inherit;
}

/* === 佈局結構 === */
.layout-with-sidebar {
  display: flex;
  min-height: 100vh;
}

/* === 側邊欄 === */
.sidebar {
  width: 200px;
  background: var(--white);
  border-right: 1px solid var(--border-gray);
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-gray);
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
}

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

.sidebar-nav-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: var(--text-gray);
  font-size: 14px;
  transition: all 0.2s;
}

.sidebar-nav-item:hover {
  background: #f9f9f9;
  color: var(--text-dark);
}

.sidebar-nav-item.active {
  background: #f0f0f0;
  color: var(--text-dark);
  font-weight: 500;
}

.sidebar-nav-icon {
  width: 18px;
  height: 18px;
  margin-right: 12px;
  flex-shrink: 0;
}

/* === 主內容區 === */
.main-content {
  flex: 1;
  margin-left: 200px;
  display: flex;
  flex-direction: column;
}

/* === 頂部欄 === */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border-gray);
  padding: 0 32px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 15px;
  color: var(--text-dark);
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-name {
  font-size: 14px;
  color: var(--text-dark);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

/* === 內容區 === */
.wrap {
  padding: 32px;
  flex: 1;
}

/* === 歡迎區塊 === */
.welcome-section {
  margin-bottom: 32px;
}

.welcome-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.welcome-subtitle {
  font-size: 14px;
  color: var(--text-gray);
}

/* === 統計卡片網格 === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.2s;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

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

.stat-card-title {
  font-size: 13px;
  color: var(--text-gray);
  font-weight: 400;
}

.stat-card-icon {
  width: 20px;
  height: 20px;
  color: var(--text-light);
  flex-shrink: 0;
}

.stat-card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1;
  margin-bottom: 8px;
}

.stat-card-status {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 8px;
}

.stat-card-status.success {
  color: var(--green-success);
}

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

/* === 快速操作區 === */
.quick-actions {
  margin-bottom: 32px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.section-subtitle {
  font-size: 12px;
  color: var(--text-gray);
  margin-bottom: 16px;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.action-card {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.2s;
}

.action-card:hover {
  border-color: var(--blue-primary);
  box-shadow: var(--shadow-md);
}

.action-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #e8f2ff;
}

.action-card-icon svg {
  width: 100%;
  height: 100%;
  color: var(--blue-primary);
}

.action-card-icon.green {
  background: #e6f7ed;
}

.action-card-icon.green svg {
  color: var(--green-success);
}

.action-card-content {
  flex: 1;
}

.action-card-content h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.action-card-content p {
  font-size: 12px;
  color: var(--text-gray);
}

/* === 按鈕 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-gray);
  background: var(--white);
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--bg-gray);
}

.btn.primary {
  background: var(--blue-primary);
  border-color: var(--blue-primary);
  color: white;
}

.btn.primary:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
}

.btn.danger {
  background: var(--red-danger);
  border-color: var(--red-danger);
  color: white;
}

.btn.danger:hover {
  background: #dc2626;
}

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

/* === 卡片 === */
.card {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.card p {
  font-size: 14px;
  color: var(--text-gray);
  line-height: 1.6;
  margin-bottom: 16px;
}

/* === 提示訊息 === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert.success {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #166534;
}

.alert.info {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
}

.alert.danger {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

/* === 表單 === */
.form label {
  display: block;
  margin-bottom: 16px;
}

.form label span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-dark);
}

.form input,
.form select,
.form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-gray);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-dark);
  background: var(--white);
  transition: all 0.2s;
}

.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--blue-primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form.inline {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

/* === 表格 === */
.table {
  width: 100%;
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius);
  border-collapse: collapse;
  overflow: hidden;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-gray);
}

.table th {
  background: #fafafa;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-gray);
  text-transform: uppercase;
}

/* 確保凍結的標題列 z-index 高於文字覆蓋層 */
.table thead,
#overview thead {
  position: relative;
  z-index: 100;
}

/* 修正兩行標題列的 sticky 定位 */
.table thead tr:first-child th,
#overview thead tr:first-child th {
  position: sticky;
  top: 0;
  background: #fafafa;
  z-index: 100;
}

.table thead tr:nth-child(2) th,
#overview thead tr:nth-child(2) th {
  position: sticky;
  top: 28px; /* 第一行高度約 28px */
  background: #fafafa;
  z-index: 100;
}

.table thead th,
#overview thead th {
  background: #fafafa;
  position: relative;
  z-index: 100;
}

/* 確保凍結的標題列 z-index 高於文字覆蓋層 */
.table thead,
#overview thead {
  position: sticky;
  top: 0;
  z-index: 100;
}

.table thead th,
#overview thead th {
  background: #fafafa;
  position: relative;
  z-index: 100;
}

/* 確保凍結的標題行背景完全覆蓋 */
.table thead tr,
#overview thead tr {
  background: #fafafa;
}

.table tbody tr:hover {
  background: #fafafa;
}

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

.table .ellipsis {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 跨房源總覽格子內文字樣式 */
.first-blocked-cell,
.first-booked-cell {
  position: relative;
  overflow: visible !important;
}

/* 修正文字跨越多格顯示 - 提高 z-index 並確保文字在最上層 */
.booking-label {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6), -1px -1px 2px rgba(0, 0, 0, 0.3);
  z-index: 9999;
  pointer-events: none;
  max-width: none;
  overflow: visible;
}

/* 確保表格單元格不會裁切文字 */
.overview-table td,
#overview td,
.table td {
  overflow: visible !important;
  position: relative;
}

/* 確保表格結構允許文字溢出 */
.overview-table,
#overview {
  overflow: visible !important;
  border-collapse: separate !important;
  border-spacing: 0;
}

.overview-table-container,
.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
}

/* 確保表格的 tbody 和 tr 也允許溢出 */
.overview-table tbody,
.overview-table tr,
#overview tbody,
#overview tr {
  overflow: visible !important;
}

/* === 登入頁面 === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--white);
}

.login-card {
  background: var(--white);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  text-align: center;
}

/* === 工具列 === */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* === 日曆 === */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-gray);
}

.day {
  min-height: 100px;
  background: #fafafa;
  border: 1px solid var(--border-gray);
  border-radius: 6px;
  padding: 8px;
  position: relative;
  transition: all 0.2s;
}

.day:hover {
  border-color: var(--blue-primary);
  box-shadow: var(--shadow-sm);
}

.day.muted {
  opacity: 0.4;
}

.date {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  color: var(--text-gray);
  font-weight: 500;
}

.badge {
  margin-top: 20px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
  font-weight: 500;
}

.badge.blocked {
  background: #fee;
  color: #c00;
  border: 1px solid #fcc;
}

.badge.booked {
  background: #efe;
  color: #060;
  border: 1px solid #cfc;
}

.hint {
  font-size: 12px;
  color: var(--text-gray);
  margin-top: 8px;
}

/* 新增匯入來源區塊樣式 */
.import-sources-section {
  margin-top: 2rem;
}

.import-sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.import-source-card {
  display: block;
  padding: 1.5rem;
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
}

.import-source-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.import-source-card.add-new {
  border-style: dashed;
  border-color: #d1d5db;
}

.import-source-card.add-new:hover {
  border-color: #10b981;
}

.import-source-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  padding: 0.75rem;
  background: #eff6ff;
  border-radius: 8px;
}

.import-source-card.add-new .import-source-icon {
  background: #f0fdf4;
}

.import-source-icon svg {
  width: 100%;
  height: 100%;
  color: #3b82f6;
}

.import-source-card.add-new .import-source-icon svg {
  color: #10b981;
}

.import-source-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
}

.import-source-card p {
  margin: 0;
  font-size: 0.875rem;
  color: #6b7280;
}

/* 新增訂單管理 Modal 樣式 */
.booking-management-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--white);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

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

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-gray);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--bg-gray);
  color: var(--text-dark);
}

.modal-body {
  padding: 24px;
}

.booking-info {
  margin-bottom: 24px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg-gray);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row .label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-gray);
  min-width: 80px;
}

.info-row .value {
  font-size: 14px;
  color: var(--text-dark);
}

.info-row .value.booked {
  color: var(--green-success);
  font-weight: 600;
}

.info-row .value.blocked {
  color: var(--red-danger);
  font-weight: 600;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-buttons .btn {
  width: 100%;
  justify-content: center;
}

.modal-body .loading,
.modal-body .error {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-gray);
}

.modal-body .error {
  color: var(--red-danger);
}

.modal-body form {
  margin-top: 20px;
}

.modal-body form label {
  display: block;
  margin-bottom: 16px;
}

.modal-body form label span,
.modal-body form label > text {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-dark);
}

.modal-body form input,
.modal-body form select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-gray);
  border-radius: 6px;
  font-size: 14px;
}

.modal-body form input:focus,
.modal-body form select:focus {
  outline: none;
  border-color: var(--blue-primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-buttons {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.form-buttons .btn {
  flex: 1;
}

.modal-body h4 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dark);
}

.modal-body .hint {
  font-size: 13px;
  color: var(--text-gray);
  margin-bottom: 16px;
  padding: 10px;
  background: var(--bg-gray);
  border-radius: 6px;
}

/* === 響應式設計 === */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .main-content {
    margin-left: 0;
  }

  .wrap {
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .actions-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0 16px;
  }
}
