:root {
  --primary: #1e3a8a;
  --primary-hover: #172554;
  --accent-blue: #2563eb;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #cbd5e1;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --success: #059669;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Pretendard", "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-dark);
  line-height: 1.5;
  padding-bottom: 70px;
}

/* Header */
.app-header {
  background-color: var(--primary);
  color: white;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

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

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-badge {
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.18);
  padding: 3px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sync-badge.synced {
  background: rgba(16, 185, 129, 0.25);
  color: #a7f3d0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-hdr {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.2s;
}

.btn-icon-hdr:hover, .btn-icon-hdr:active {
  background: rgba(255, 255, 255, 0.28);
}

.btn-search-hdr {
  background: #2563eb;
}
.btn-search-hdr:hover {
  background: #1d4ed8;
}

/* Main Container */
.main-container {
  max-width: 1060px;
  margin: 12px auto;
  padding: 0 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Top Info Row */
.info-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 4px;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.input-date {
  font-size: 0.95rem;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #fff;
  width: 135px;
}

.btn-mini {
  padding: 6px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  background: #f1f5f9;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.btn-today {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.input-day {
  width: 65px;
  padding: 6px;
  text-align: center;
  font-weight: 600;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.9rem;
}

.weather-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.select-weather {
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
}

.input-location {
  width: 85px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.9rem;
}

.schedule-group {
  flex: 1;
  min-width: 280px;
}

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

.textarea-sched {
  width: 100%;
  height: 48px;
  padding: 6px 8px;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  resize: vertical;
  line-height: 1.4;
  font-family: inherit;
}

/* Sections */
.section-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.title-work { color: #1e40af; }
.title-misc { color: #854d0e; }
.title-shop { color: #047857; }

.section-textarea {
  width: 100%;
  min-height: 120px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  resize: vertical;
  line-height: 1.5;
  font-family: inherit;
  background: #fff;
}

.section-textarea:focus, .textarea-sched:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

/* Purchase Table */
.table-header-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.shop-total-badge {
  font-size: 1rem;
  font-weight: 700;
  color: var(--success);
  background: var(--success-bg);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #a7f3d0;
}

.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #fff;
}

.purchase-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.purchase-table th {
  background: #f1f5f9;
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  white-space: nowrap;
}

.purchase-table td {
  padding: 4px 6px;
  border-bottom: 1px solid #e2e8f0;
}

.purchase-table input {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: inherit;
}

.purchase-table input:focus {
  border-color: var(--accent-blue);
  background: #f8fafc;
  outline: none;
}

.purchase-table td.col-amount input {
  background: #f8fafc;
  font-weight: 700;
  text-align: right;
  color: #0f172a;
}

.btn-del-row {
  background: transparent;
  color: var(--danger);
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-del-row:hover { background: var(--danger-bg); }

/* Bottom Action Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  justify-content: center;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}

.btn-action {
  padding: 10px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s;
}

.btn-action:active {
  transform: scale(0.98);
}

.btn-save {
  background: #1e3a8a;
  color: white;
}
.btn-save:hover { background: #172554; }

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-dark);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: #e2e8f0; }

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.modal-header {
  background: var(--primary);
  color: white;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close-modal {
  background: transparent;
  color: white;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* Search Modal Styles */
.search-input-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input {
  flex: 1;
  padding: 9px 12px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.search-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
  height: 480px;
}

.search-list {
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #f8fafc;
}

.search-item {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  cursor: pointer;
}

.search-item:hover { background: #e0f2fe; }
.search-item.active { background: #bae6fd; font-weight: 700; }

.search-item-date { font-size: 0.85rem; color: #0369a1; }
.search-item-snippet { font-size: 0.85rem; color: #475569; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search-preview {
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 14px;
  background: #fffdf7;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Highlighting matching search terms */
.highlight-kw {
  color: #dc2626 !important;
  font-weight: 800;
  background-color: #fee2e2;
  padding: 0 3px;
  border-radius: 3px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  body {
    padding-bottom: 80px;
  }
  .info-grid {
    flex-direction: column;
    align-items: stretch;
  }
  .input-date, .input-location, .schedule-group {
    width: 100%;
  }
  .search-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .search-list {
    max-height: 180px;
  }
  .search-preview {
    max-height: 260px;
  }
}
