:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --border: #e3e3e8;
  --text: #1b1c1f;
  --text-muted: #6b6d76;
  --accent: #4f5ef0;
  --accent-contrast: #ffffff;
  --danger: #e0503a;
  --success: #1f9d55;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 20, 30, 0.06), 0 1px 2px rgba(20, 20, 30, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #201f24;
    --border: #33333a;
    --text: #ececef;
    --text-muted: #97979f;
    --accent: #8f97ff;
    --accent-contrast: #14141a;
    --danger: #ff7a63;
    --success: #4bd07d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.24);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.auth-card p.sub {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 0.9rem;
}

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

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 16px;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  width: 100%;
  font-weight: 600;
  border: none;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
}

.btn-small {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-confirm {
  background: var(--success);
  color: white;
  border: none;
  padding: 6px 12px;
  font-weight: 600;
}

.btn-deny {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 6px 12px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -8px 0 12px;
  min-height: 1em;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 7px 16px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 600;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

main {
  flex: 1;
  padding: 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Calendar */
.calendar-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .calendar-layout { grid-template-columns: 1fr; }
}

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-left: 4px;
}

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

.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.view-toggle-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
}

.view-toggle-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.calendar-grid {
  position: relative;
  display: grid;
  grid-template-columns: 56px repeat(7, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.cal-head {
  padding: 8px 4px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.cal-head:first-child { border-left: none; }
.cal-head.today { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

.cal-head-date {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}
.cal-head.today .cal-head-date { color: var(--accent); }

.cal-hour-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: right;
  padding: 2px 6px 0 0;
  border-top: 1px solid var(--border);
}

.cal-cell {
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  min-height: 22px;
  position: relative;
  cursor: pointer;
}
.cal-cell:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.cal-cell.today { background: color-mix(in srgb, var(--accent) 4%, transparent); }

/* Month view */
.calendar-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.month-cell {
  min-height: 92px;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.month-cell:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.month-day-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.month-cell.today .month-day-num {
  color: var(--accent-contrast);
  background: var(--accent);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.month-cell.other-month { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.month-cell.other-month .month-day-num { color: var(--text-muted); opacity: 0.5; }

.month-event-chip {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 5px;
  font-size: 0.7rem;
  padding: 2px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.month-event-chip.pending {
  background: transparent;
  border: 1.5px dashed var(--accent);
  color: var(--text);
}

.month-more {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.cal-event {
  position: absolute;
  left: 2px;
  right: 2px;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 3px 5px;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
}

.cal-event.pending {
  background: transparent;
  border: 2px dashed var(--accent);
  color: var(--text);
}

.sidebar h2 {
  font-size: 0.95rem;
  margin: 0 0 10px;
}

.proposal-card {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.proposal-card:last-child { border-bottom: none; }

.proposal-reason {
  font-size: 0.85rem;
  margin: 0 0 8px;
}

.proposal-actions { display: flex; gap: 8px; }

.empty-state {
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* Chat */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
  min-height: 420px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-style: italic;
}

/* Markdown inside assistant bubbles */
.bubble :first-child { margin-top: 0; }
.bubble :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 8px; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble h4, .bubble h5, .bubble h6 { margin: 8px 0 4px; font-size: 0.95rem; }
.bubble code {
  background: color-mix(in srgb, var(--text) 12%, transparent);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble pre {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: 8px 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.bubble pre code { background: none; padding: 0; }
.bubble a { color: inherit; text-decoration: underline; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.chat-input-row input { margin: 0; flex: 1; min-width: 0; }
.chat-input-row button { width: auto; flex: none; padding: 0 18px; }

.change-card {
  align-self: flex-start;
  max-width: 85%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg);
}

.change-card .badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  margin-bottom: 6px;
}

.change-card.resolved .badge {
  background: var(--border);
  color: var(--text-muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.modal h2 { margin-top: 0; font-size: 1.1rem; }

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

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.hidden { display: none !important; }
