:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --border: #e4e6f1;
  --text: #1c1f2e;
  --text-muted: #6b7086;
  --accent: #6c63ff;
  --accent-dark: #564fd8;
  --accent-soft: #eeecff;
  --danger: #e5484d;
  --success: #22c1a0;
  --warning: #ff7a59;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.05), 0 4px 16px rgba(20, 20, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
}

/* --- Buttons --- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--accent-soft); }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }

/* --- Auth screen --- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #efedff, var(--bg) 60%);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  color: var(--accent-dark);
}
.auth-sub {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13.5px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}
.auth-tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text-muted);
}
.auth-tab-btn.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: var(--shadow);
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.auth-form input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.auth-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-hint { margin: -6px 0 0; font-size: 12px; color: var(--text-muted); }
.form-error { margin: 0; color: var(--danger); font-size: 12.5px; min-height: 14px; }

/* --- App shell --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; color: var(--accent-dark); font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text-muted);
}
.tab-btn:hover { background: var(--accent-soft); }
.tab-btn.active { background: var(--accent-soft); color: var(--accent-dark); }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-chip {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
}

.content { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel h2 { margin: 0 0 20px; font-size: 20px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.panel-header h2, .panel-header h3 { margin: 0; }

/* --- Dashboard --- */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--text-muted); }
.big-stat { font-size: 32px; font-weight: 800; color: var(--accent-dark); margin-bottom: 10px; }
.dash-list { display: flex; flex-direction: column; gap: 8px; }
.dash-item { font-size: 13px; padding: 8px 10px; background: var(--bg); border-radius: 8px; }
.dash-item .meta { color: var(--text-muted); font-size: 12px; }
.empty-hint { color: var(--text-muted); font-size: 13px; padding: 10px 0; }

/* --- Tasks board --- */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.board-col h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 10px; }
.board-list { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.task-card .title { font-weight: 600; margin-bottom: 4px; }
.task-card .desc { color: var(--text-muted); font-size: 12.5px; margin-bottom: 8px; white-space: pre-wrap; }
.task-card .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-low { background: #eef2ff; color: #4f5bd5; }
.badge-normal { background: var(--accent-soft); color: var(--accent-dark); }
.badge-high { background: #ffece8; color: var(--danger); }
.assignee-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;
}
.due-date { font-size: 12px; color: var(--text-muted); }
.due-date.overdue { color: var(--danger); font-weight: 700; }
.task-actions { display: flex; gap: 6px; margin-top: 10px; }
.task-actions select { border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; font-size: 12px; }
.icon-btn {
  border: none; background: transparent; color: var(--text-muted); font-size: 13px; padding: 3px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--danger); }

/* --- Events --- */
.events-list { display: flex; flex-direction: column; gap: 10px; }
.event-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.event-date-badge {
  min-width: 58px;
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 8px;
  padding: 6px 4px;
  font-weight: 700;
  line-height: 1.2;
}
.event-date-badge .day { font-size: 18px; display: block; }
.event-date-badge .mon { font-size: 11px; text-transform: uppercase; }
.event-body { flex: 1; }
.event-title { font-weight: 600; }
.event-desc { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; white-space: pre-wrap; }
.event-time { font-size: 12px; color: var(--text-muted); }
.event-past { opacity: 0.55; }

/* --- Library --- */
.library-groups { display: flex; flex-direction: column; gap: 22px; }
.library-group h3 { font-size: 13px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.03em; margin-bottom: 10px; }
.library-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.library-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.library-card a { color: var(--accent-dark); font-weight: 600; text-decoration: none; }
.library-card a:hover { text-decoration: underline; }
.library-card .desc { color: var(--text-muted); font-size: 12.5px; margin-top: 4px; }
.library-card .meta { color: var(--text-muted); font-size: 11.5px; margin-top: 8px; }

/* --- Reference --- */
.reference-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
.reference-sidebar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.reference-page-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.ref-page-btn {
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
}
.ref-page-btn:hover { background: var(--bg); }
.ref-page-btn.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.reference-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: 300px;
}
.reference-main h1 { font-size: 24px; margin-top: 0; }
.reference-main h2 { font-size: 19px; }
.reference-main h3 { font-size: 16px; }
.reference-main p { line-height: 1.6; }
.reference-main ul { line-height: 1.6; }
.reference-main code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.ref-meta { color: var(--text-muted); font-size: 12px; margin-bottom: 16px; }
.ref-editor { width: 100%; min-height: 320px; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: ui-monospace, monospace; font-size: 13px; line-height: 1.5; }
.ref-title-input { font-size: 20px; font-weight: 700; border: none; border-bottom: 2px solid var(--border); padding: 4px 0; width: 100%; margin-bottom: 12px; }
.ref-title-input:focus { outline: none; border-color: var(--accent); }

/* --- Modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 20, 40, 0.35);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 20px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h3 { margin: 0 0 16px; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.modal input, .modal select, .modal textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.modal textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 200;
}
.toast.error { background: var(--danger); }

/* --- Responsive --- */
@media (max-width: 860px) {
  .dash-grid, .board, .library-grid { grid-template-columns: 1fr; }
  .reference-layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
}
