:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #111827;
  --primary-fg: #ffffff;
  --accent: #2563eb;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

html.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #162032;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #f8fafc;
  --primary-fg: #0f172a;
  --accent: #60a5fa;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Buttons & Inputs */
button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.15s, background 0.15s;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
.btn-full { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

input[type="text"], input[type="password"], input[type="date"], input[type="time"], select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-mascot {
  display: block;
  width: 84px;
  height: 84px;
  margin: 0 auto 12px;
}
.login-title { margin: 0 0 6px; font-size: 1.6rem; text-align: center; }
.login-subtitle { margin: 0 0 24px; text-align: center; color: var(--text-muted); font-size: 0.88rem; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; font-weight: 500; }
.error-text { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  transition: width 0.2s;
}
.sidebar.collapsed { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 4px;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  font-size: 1.08rem;
}
.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.space-switcher-wrap { margin-bottom: 14px; }
.space-select { width: 100%; font-weight: 500; }

.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary); color: var(--primary-fg); }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }
.nav-footer-btn {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.nav-footer-btn:hover { background: var(--surface-2); color: var(--text); }

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.page-title { margin: 0; font-size: 1.12rem; font-weight: 700; }
.user-badge {
  font-size: 0.84rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.main-content {
  padding: 20px 24px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title { margin: 0; font-size: 0.96rem; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.muted { color: var(--text-muted); font-size: 0.86rem; }

/* Home */
.home-greeting { margin-bottom: 16px; }
.home-greeting h2 { margin: 0 0 2px; font-size: 1.35rem; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  cursor: pointer;
  transition: transform 0.12s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-label { font-size: 0.84rem; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 1.55rem; font-weight: 700; }
.kpi-danger .kpi-value { color: var(--danger); }
.kpi-warn .kpi-value { color: var(--warn); }
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill { height: 100%; background: var(--ok); transition: width 0.25s; }

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.week-day {
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
}
.week-day.today { border-color: var(--accent); background: rgba(37, 99, 235, 0.08); font-weight: 700; }
.week-day-name { font-size: 0.78rem; color: var(--text-muted); }
.week-day-num { font-size: 1rem; margin: 2px 0; }
.week-day-dots { font-size: 0.72rem; color: var(--accent); min-height: 16px; }

.widget-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.widget-card[draggable="true"] { cursor: default; }
.drag-handle { cursor: grab; color: var(--text-muted); font-size: 0.85rem; user-select: none; }

/* Todo */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.inline-form .grow { flex: 1; min-width: 200px; }

.pill-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.pill {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.84rem;
}
.pill.active { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.todo-list { display: flex; flex-direction: column; gap: 8px; }
.todo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.todo-row-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.todo-title { font-weight: 500; word-break: break-word; }
.todo-title.done { text-decoration: line-through; color: var(--text-muted); }
.todo-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.badge-high { color: var(--danger); border-color: rgba(220, 38, 38, 0.35); }
.badge-medium { color: var(--warn); border-color: rgba(217, 119, 6, 0.35); }
.badge-low { color: var(--text-muted); }
.badge-overdue { background: rgba(220, 38, 38, 0.12); color: var(--danger); border-color: transparent; }

/* Kanban Board */
.board-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  align-items: start;
}
.board-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.board-col.drag-over { outline: 2px dashed var(--accent); }
.board-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot-todo { background: #6b7280; }
.dot-in_progress { background: #d97706; }
.dot-done { background: #16a34a; }

.kanban-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kanban-card:hover { border-color: var(--accent); }
.kanban-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* Calendar */
.calendar-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  align-items: start;
}
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-weekdays, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-weekday { text-align: center; font-size: 0.8rem; color: var(--text-muted); padding: 4px 0; font-weight: 600; }
.cal-cell {
  min-height: 76px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.cal-cell.other-month { opacity: 0.4; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.selected { background: rgba(250, 204, 21, 0.16); border-color: var(--warn); }
.cal-num { font-size: 0.82rem; font-weight: 600; display: flex; justify-content: space-between; }
.cal-num.holiday, .cal-num.sun { color: var(--danger); }
.cal-holiday-label { font-size: 0.68rem; color: var(--danger); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip {
  font-size: 0.72rem;
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Routine */
.routine-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.history-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.history-table th, .history-table td { border: 1px solid var(--border); padding: 6px; text-align: center; }
.history-table th:first-child, .history-table td:first-child { text-align: left; min-width: 140px; }
.history-cell { cursor: pointer; user-select: none; }
.history-cell.checked { background: rgba(22, 163, 74, 0.18); color: var(--ok); font-weight: 700; }

/* Wiki */
.wiki-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 14px;
  min-height: 540px;
}
.wiki-sidebar { display: flex; flex-direction: column; gap: 10px; }
.wiki-page-list { display: flex; flex-direction: column; gap: 4px; max-height: 440px; overflow-y: auto; }
.wiki-page-item {
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.wiki-page-item:hover { background: var(--surface-2); }
.wiki-page-item.active { background: var(--surface-2); border-color: var(--accent); font-weight: 600; }
.wiki-item-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.wiki-item-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.wiki-tag-pill {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
}
.wiki-tag-filter-bar { display: flex; flex-wrap: wrap; gap: 4px; }
.wiki-editor-area { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.wiki-meta-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.wiki-textarea { width: 100%; min-height: 360px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9rem; line-height: 1.6; }
.wiki-preview {
  min-height: 360px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.65;
  overflow-x: auto;
}
.wiki-preview h1, .wiki-preview h2, .wiki-preview h3 { margin: 14px 0 8px; line-height: 1.3; }
.wiki-preview h1 { font-size: 1.45rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.wiki-preview h2 { font-size: 1.2rem; }
.wiki-preview h3 { font-size: 1.05rem; }
.wiki-preview p { margin: 6px 0; }
.wiki-preview ul { margin: 6px 0; padding-left: 20px; }
.wiki-preview blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  color: var(--text-muted);
}
.wiki-preview code {
  background: rgba(127, 127, 127, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86em;
}
.wiki-preview pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.wiki-preview pre code { background: transparent; padding: 0; color: inherit; }
.wiki-preview table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.9rem; }
.wiki-preview th, .wiki-preview td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.wiki-preview th { background: var(--surface); font-weight: 600; }
.wiki-preview a { color: var(--accent); text-decoration: underline; }

/* Snippets */
.snippet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}
.snippet-code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.83rem;
  overflow-x: auto;
  max-height: 220px;
  margin: 8px 0;
  white-space: pre;
}

/* Drive */
.drive-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 14px;
}
.drive-dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}
.drive-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.drive-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.86rem; font-weight: 500; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-palette { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.active { border-color: var(--text); transform: scale(1.1); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed;
  bottom: 76px;
  right: 20px;
  background: var(--primary);
  color: var(--primary-fg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  z-index: 60;
  box-shadow: var(--shadow);
}

/* Responsive */
.mobile-only { display: none; }
.mobile-bottom-nav { display: none; }
.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
}

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .widget-grid, .board-columns, .calendar-layout, .routine-top, .wiki-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.mobile-open { display: flex !important; transform: translateX(0); }
  .main-content { padding: 14px 12px 84px; }
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 25;
  }
  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
  }
  .mobile-tab.active { color: var(--accent); font-weight: 700; }
  .mobile-tab small { font-size: 0.7rem; }
}
