:root {
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --sidebar:   #0f172a;
  --text:      #0f172a;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --primary:   #6366f1;
  --primary-h: #4f46e5;
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --sw:        260px;
  --nh:        62px;
  --shadow: 0 15px 36px rgba(15, 23, 42, .12);
}

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

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sw);
  background: var(--sidebar);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 2px;
  z-index: 200;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  margin-bottom: 6px;
  min-width: 0;
}

.brand-mark {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 7px;
  display: grid; place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}

.brand-mark svg { width: 15px; height: 15px; stroke: #fff; }
.brand-text { min-width: 0; flex: 1; }

.brand-name {
  font-size: .88rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub  {
  font-size: .7rem;
  color: rgba(255,255,255,.38);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 7px;
  text-decoration: none;
  font-size: .84rem;
  font-weight: 500;
  color: rgba(255,255,255,.5);
  transition: background .13s, color .13s;
}

.nav-link:hover  { background: rgba(255,255,255,.07); color: rgba(255,255,255,.85); }
.nav-link.active { background: rgba(99,102,241,.25);  color: #fff; }

.nav-icon { width: 17px; height: 17px; display: grid; place-items: center; flex-shrink: 0; }
.nav-icon svg { width: 17px; height: 17px; }

.sidebar-promo {
  margin-top: auto;
  padding-top: 16px;
}

.sidebar-promo-inner {
  background: rgba(99,102,241,.15);
  border: 1px solid rgba(99,102,241,.25);
  border-radius: 10px;
  padding: 14px;
}

.sidebar-promo-inner p:first-child { font-size: .8rem; font-weight: 700; color: #fff; margin-bottom: 4px; }
.sidebar-promo-inner p:last-of-type { font-size: .73rem; color: rgba(255,255,255,.45); line-height: 1.5; margin-bottom: 12px; }

.main {
  margin-left: var(--sw);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.navbar {
  height: var(--nh);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.menu-btn {
  display: none;
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  place-items: center;
}

.nav-search {
  flex: 1;
  max-width: 300px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
}

.nav-search svg { width: 14px; height: 14px; color: var(--muted); flex-shrink: 0; }
.nav-search input { border: none; background: none; outline: none; font-family: inherit; font-size: .83rem; color: var(--text); width: 100%; }
.nav-search input::placeholder { color: var(--muted); }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; position: relative; }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted);
  transition: background .13s, color .13s;
}

.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: grid; place-items: center;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.page {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1   { font-size: 1.3rem; font-weight: 700; }
.page-header .sub { font-size: .82rem; color: var(--muted); margin-top: 3px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-family: inherit; font-size: .83rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: background .13s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-ghost    { background: var(--card); color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover    { color: var(--text); }
.btn.action-delete {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}
.btn.action-delete:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn-small { padding: 7px 12px; font-size: .76rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stats.stats-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stat { padding: 18px 20px; }
.stat-label { font-size: .73rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.9rem; font-weight: 800; margin: 8px 0 4px; line-height: 1; }
.stat-hint  { font-size: .76rem; color: var(--muted); }
.stat-hint.up   { color: var(--green); }
.stat-hint.down { color: var(--red); }

.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }

.notion-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.notion-toolbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.notion-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.notion-search {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  width: 200px;
}

.notion-search svg { width: 13px; height: 13px; color: var(--muted); flex-shrink: 0; }
.notion-search input {
  border: none;
  background: none;
  outline: none;
  font: inherit;
  font-size: .8rem;
  color: var(--text);
  width: 100%;
}

.notion-sort {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 9px;
}

.notion-sort svg { width: 13px; height: 13px; color: var(--muted); flex-shrink: 0; }
.notion-sort select {
  border: none;
  background: none;
  outline: none;
  font: inherit;
  font-size: .78rem;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}

table { width: 100%; border-collapse: collapse; }

th {
  font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  font-size: .855rem;
  color: var(--text);
  padding: 0 16px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}

th:not(:last-child), td:not(:last-child) { border-right: 1px solid var(--border); }

td.tags-cell {
  white-space: normal;
  max-width: 200px;
  min-width: 120px;
  padding-top: 10px;
  padding-bottom: 10px;
  height: auto;
  vertical-align: top;
}

td.actions-cell {
  width: 1%;
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 12px;
  position: sticky;
  right: 0;
  z-index: 2;
  background: #fff;
  box-shadow: -1px 0 0 var(--border);
}

th:last-child {
  position: sticky;
  right: 0;
  z-index: 3;
  background: #fff;
  box-shadow: -1px 0 0 var(--border);
}

.table-text-cell { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
.table-text-clip {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.view-all-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: .76rem;
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
}

.row-actions {
  opacity: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}

.row-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  display: grid; place-items: center;
}

.row-btn:hover { background: var(--border); color: var(--text); }
.row-btn svg { width: 14px; height: 14px; }

.action-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}
.action-icon-btn svg { width: 14px; height: 14px; }
.action-icon-btn:hover { background: var(--bg); border-color: #c7d0db; color: var(--text); }

.action-icon-view:hover {
  color: #0284c7;
  border-color: rgba(2,132,199,.35);
  background: rgba(2,132,199,.08);
}

.action-icon-edit:hover {
  color: var(--primary);
  border-color: rgba(99,102,241,.35);
  background: rgba(99,102,241,.08);
}

.action-icon-delete:hover {
  color: var(--red);
  border-color: rgba(239,68,68,.35);
  background: rgba(239,68,68,.08);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 500;
  background: #f1f5f9;
  color: #475569;
  margin: 2px 3px 2px 0;
}

.muted-dash { color: var(--muted); font-size: .85rem; }

.pager-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: .73rem;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.table-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.flash-wrap { display: flex; flex-direction: column; gap: 10px; }
.flash {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-size: .82rem;
  font-weight: 600;
}
.flash-success {
  color: #166534;
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.flash-error {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px 20px 20px;
}
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: .73rem; font-weight: 600; color: var(--muted); }
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  font-size: .83rem;
  color: var(--text);
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(99,102,241,.2);
  border-color: var(--primary);
}

.field input[type="color"] { padding: 2px; height: 38px; border-radius: 8px; cursor: pointer; }

.drawer {
  position: fixed;
  inset: 0;
  z-index: 400;
  visibility: hidden;
  pointer-events: none;
}

.drawer.open { visibility: visible; pointer-events: auto; }

.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .35);
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: min(560px, 100%);
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 25px rgba(15, 23, 42, .12);
  transform: translateX(100%);
  transition: transform .2s ease;
  overflow-y: auto;
}

.drawer.open .drawer-panel { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h2 { font-size: .94rem; font-weight: 700; }

.drawer-form { padding-top: 14px; }
.drawer-submit-row { grid-column: 1 / -1; display: flex; justify-content: center; }

.view-grid {
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.view-item { display: flex; flex-direction: column; gap: 6px; }
.view-item.full { grid-column: 1 / -1; }
.view-item > span { font-size: .73rem; font-weight: 600; color: var(--muted); }
.view-value {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  font-size: .83rem;
  display: flex;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  visibility: hidden;
  pointer-events: none;
}
.modal.open { visibility: visible; pointer-events: auto; }
.modal-overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-panel {
  position: relative;
  width: min(520px, calc(100% - 24px));
  margin: 8vh auto 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, .22);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.longtext-modal-panel { width: min(640px, calc(100% - 24px)); }
.longtext-modal-body {
  padding: 16px;
  font-size: .88rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: min(70vh, 620px);
  overflow: auto;
}

.auth-shell {
  min-height: 100vh;
  background: radial-gradient(circle at top, #e0e7ff 0%, #f8fafc 45%, #f1f5f9 100%);
  display: grid;
  place-items: center;
  padding: 20px;
  position: relative;
}

.auth-with-bg {
  background-image: url("https://images.unsplash.com/photo-1497366811353-6870744d04b2?auto=format&fit=crop&w=1920&q=80");
  background-size: cover;
  background-position: center;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(15, 23, 42, .64), rgba(51, 65, 85, .50));
  backdrop-filter: blur(4px);
}

.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .09);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1;
  align-items: center;
  text-align: center;
}

.auth-card h1 { font-size: 1.35rem; font-weight: 800; }

.auth-glass {
  background: rgba(255, 255, 255, .84);
  border: 1px solid rgba(255, 255, 255, .62);
  backdrop-filter: blur(16px);
}

.auth-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  width: 100%;
}

.auth-app-name {
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 700;
  color: #334155;
}

.auth-card .field,
.auth-card .flash-wrap,
.auth-card .flash {
  width: 100%;
  text-align: left;
}

.auth-card .btn {
  width: 100%;
  justify-content: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .73rem;
  font-weight: 600;
}

.tag.todo { background: #e2e8f0; color: #475569; }
.tag.in_progress { background: #dbeafe; color: #1d4ed8; }
.tag.blocked { background: #fee2e2; color: #dc2626; }
.tag.review { background: #ede9fe; color: #7c3aed; }
.tag.done { background: #dcfce7; color: #16a34a; }
.tag.archived { background: #f1f5f9; color: #334155; }

.priority-low { color: #16a34a; }
.priority-medium { color: #d97706; }
.priority-high { color: #ea580c; }
.priority-urgent { color: #dc2626; font-weight: 700; }

.empty-state { text-align: center; color: var(--muted); padding: 24px; }

.inline-form { display: inline-flex; align-items: center; gap: 8px; }
.inline-form input { width: 180px; border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; font: inherit; font-size: .8rem; }

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

@media (max-width: 1024px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats.stats-5 { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
}

@media (max-width: 540px) {
  .stats { grid-template-columns: 1fr; }
  .stats.stats-5 { grid-template-columns: 1fr; }
  .page { padding: 20px 16px; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .notion-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .notion-toolbar-right { width: 100%; }
  .notion-search { width: 100%; }
  .table-pager { flex-direction: column; align-items: flex-start; }
  .view-grid { grid-template-columns: 1fr; }
}
