/* ==========================================================================
   AffinityX — design system
   Minimal, premium, high legibility. Light + dark.
   ========================================================================== */

:root {
  --bg:        #f6f6f8;
  --surface:   #ffffff;
  --surface-2: #fafafb;
  --border:    #e6e6ea;
  --border-2:  #d9d9df;
  --text:      #111114;
  --text-2:    #5a5a63;
  --text-3:    #8a8a93;
  --accent:    #111114;
  --accent-fg: #ffffff;

  --new-bg:      #ffffff;
  --new-line:    #d9d9df;
  --prog-bg:     #fff8e8;
  --prog-line:   #f0c65a;
  --prog-text:   #8a6100;
  --done-bg:     #eefaf1;
  --done-line:   #63c07f;
  --done-text:   #1f6d3a;
  --danger:      #c0392b;

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --shadow-1: 0 1px 2px rgba(17,17,20,.05), 0 1px 3px rgba(17,17,20,.04);
  --shadow-2: 0 12px 32px rgba(17,17,20,.10), 0 2px 8px rgba(17,17,20,.06);
  --sidebar-w: 264px;
  --header-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e0e11;
    --surface:   #17171b;
    --surface-2: #1d1d22;
    --border:    #2a2a31;
    --border-2:  #35353d;
    --text:      #f2f2f4;
    --text-2:    #a6a6b0;
    --text-3:    #7c7c87;
    --accent:    #f2f2f4;
    --accent-fg: #0e0e11;

    --new-bg:    #17171b;
    --new-line:  #35353d;
    --prog-bg:   #241f10;
    --prog-line: #a37c1a;
    --prog-text: #e8c26a;
    --done-bg:   #10231a;
    --done-line: #2f7a4d;
    --done-text: #7fd4a0;
    --danger:    #ef6a5b;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 16px 40px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--text-3); font-size: 13.5px; }
.is-hidden { display: none !important; }

/* ------------------------------------------------------------------ brand */

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text); font-weight: 650;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700; letter-spacing: -0.02em;
}
.brand-name { font-size: 15px; letter-spacing: -0.02em; }
.brand-name span { color: var(--text-3); }
.brand--auth { margin-bottom: 24px; }

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.nav-toggle { display: none; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--r-md);
  padding: 8px 14px;
  font: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer; text-decoration: none;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { opacity: .9; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.is-active { color: var(--text); border-color: var(--border-2); background: var(--surface-2); }
.btn-soft { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-soft:hover { border-color: var(--border-2); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger-ghost:hover { border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 11px 14px; font-size: 14px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid transparent;
  color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-sm { width: 28px; height: 28px; }

/* ---------------------------------------------------------------- layout */

.layout { display: flex; min-height: calc(100vh - var(--header-h)); align-items: stretch; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; justify-content: space-between;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}
.side-nav { padding: 14px 12px; }

.side-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--text-2); text-decoration: none; font-size: 13.5px; font-weight: 500;
}
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link.is-active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.side-link--top { margin-bottom: 6px; }

.side-heading {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 6px;
  font-size: 11px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3);
}
.side-add {
  border: none; background: transparent; color: var(--text-3);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 5px;
}
.side-add:hover { color: var(--text); background: var(--surface-2); }

.project-list { list-style: none; margin: 0; padding: 0; }
.project-item { margin-bottom: 1px; }
.project-link .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border-2); flex: 0 0 6px;
}
.project-link.is-active .dot { background: var(--text); }
.project-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-empty { padding: 8px 10px; color: var(--text-3); font-size: 13px; }

.submenu { list-style: none; margin: 2px 0 8px; padding: 0 0 0 25px; position: relative; }
.submenu::before {
  content: ''; position: absolute; left: 14px; top: 4px; bottom: 4px;
  width: 1px; background: var(--border);
}
.sub-link {
  display: block; padding: 6px 10px; border-radius: var(--r-sm);
  color: var(--text-3); text-decoration: none; font-size: 13px;
}
.sub-link:hover { background: var(--surface-2); color: var(--text); }
.sub-link.is-active { color: var(--text); font-weight: 600; background: var(--surface-2); }

.side-foot { padding: 12px; border-top: 1px solid var(--border); }
.side-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 650; flex: 0 0 30px;
}
.side-user-meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.side-user-meta strong { font-size: 13px; font-weight: 600; }
.side-user-meta small { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-signout {
  width: 100%; padding: 7px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-2); font: inherit; font-size: 12.5px; cursor: pointer;
}
.side-signout:hover { background: var(--surface-2); color: var(--text); }

.main { flex: 1 1 auto; min-width: 0; }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 28px 72px; }
.page--narrow { max-width: 720px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-title { font-size: 25px; line-height: 1.2; }
.page-sub { color: var(--text-3); font-size: 13.5px; margin-top: 4px; }
.page-sub a { color: var(--text-2); }
.breadcrumb { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; margin-bottom: 4px; }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }

/* ------------------------------------------------------------- panels etc */

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-1);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title { font-size: 14px; font-weight: 650; margin-bottom: 12px; }
.panel-head .panel-title { margin-bottom: 12px; }
.sub-title { font-size: 13px; font-weight: 650; color: var(--text-2); }
.link-sm { font-size: 12.5px; color: var(--text-3); text-decoration: none; }
.link-sm:hover { color: var(--text); }
.divider { height: 1px; background: var(--border); margin: 6px 0; }
.platform-text { white-space: pre-wrap; color: var(--text-2); font-size: 14px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split > .panel { margin-bottom: 16px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 14px 16px; box-shadow: var(--shadow-1);
}
.stat-value { display: block; font-size: 24px; font-weight: 680; letter-spacing: -0.02em; }
.stat-label { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stat--progress { border-color: var(--prog-line); }
.stat--complete { border-color: var(--done-line); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.project-card {
  display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-1);
  transition: border-color .14s ease, transform .14s ease;
}
.project-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.project-card h3 { font-size: 15.5px; }
.project-card-domain { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.project-card-go { display: block; margin-top: 14px; font-size: 12.5px; color: var(--text-3); }

.empty-state {
  background: var(--surface); border: 1px dashed var(--border-2);
  border-radius: var(--r-lg); padding: 44px 24px; text-align: center;
}
.empty-state h2 { font-size: 16px; }
.empty-state p { color: var(--text-3); font-size: 13.5px; margin: 6px 0 16px; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border); font-size: 13.5px;
}
.mini-row:first-child { border-top: none; }
.mini-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ forms */

.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: block; }
.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.label-hint { font-weight: 450; color: var(--text-3); font-size: 11.5px; margin-left: 6px; }
.input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-2); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.input:focus {
  outline: none; border-color: var(--text-3);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-3) 18%, transparent);
}
.input:disabled { background: var(--surface-2); color: var(--text-3); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.textarea-lg { min-height: 180px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.input-sm { padding: 7px 10px; font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-hint { font-size: 12.5px; color: var(--text-3); }
.form-error { font-size: 13px; color: var(--danger); }

.alert { padding: 10px 13px; border-radius: var(--r-md); font-size: 13.5px; margin-bottom: 14px; border: 1px solid; }
.alert-ok { background: var(--done-bg); border-color: var(--done-line); color: var(--done-text); }
.alert-err { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: var(--danger); color: var(--danger); }

/* ------------------------------------------------------------------- tags */

.tag-picker { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; min-height: 30px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text-2); font-size: 12.5px; cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.tag-chip:hover { border-color: var(--text-3); }
.tag-chip.is-selected { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.tag-chip .tag-x {
  border: none; background: transparent; color: inherit; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0; opacity: .5;
}
.tag-chip .tag-x:hover { opacity: 1; }
.tag-chip input.tag-edit {
  border: none; background: transparent; color: inherit; font: inherit; font-size: 12.5px;
  width: 90px; outline: none;
}
.tag-add { display: flex; gap: 8px; }
.tag-add .input { flex: 1 1 auto; }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-block; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2);
}

/* ------------------------------------------------------------------ tasks */

.task-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.filter-group {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
}
.filter {
  border: none; background: transparent; color: var(--text-3);
  font: inherit; font-size: 12.5px; font-weight: 550;
  padding: 5px 11px; border-radius: 8px; cursor: pointer;
}
.filter:hover { color: var(--text); }
.filter.is-active { background: var(--surface-2); color: var(--text); }

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--new-line); border-left-width: 3px;
  border-radius: var(--r-md); background: var(--new-bg);
  box-shadow: var(--shadow-1);
  transition: background .16s ease, border-color .16s ease, opacity .16s ease;
}
.task-row.status-in_progress { background: var(--prog-bg); border-color: var(--prog-line); }
.task-row.status-complete { background: var(--done-bg); border-color: var(--done-line); }
.task-row.status-complete .task-title { color: var(--done-text); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--done-text) 45%, transparent); }
.task-title { flex: 1 1 auto; min-width: 0; font-size: 14px; word-break: break-word; }
.task-actions { flex: 0 0 auto; opacity: 0; transition: opacity .14s ease; }
.task-row:hover .task-actions { opacity: 1; }
.status-btn { border: none; background: transparent; padding: 0; cursor: pointer; flex: 0 0 auto; }

.status-pill {
  display: inline-block; min-width: 92px; text-align: center;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .01em;
  border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text-2);
}
.status-pill--in_progress { background: var(--prog-line); border-color: var(--prog-line); color: #1c1400; }
.status-pill--complete { background: var(--done-line); border-color: var(--done-line); color: #04220f; }

/* ----------------------------------------------------------------- modals */

.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,10,14,.5); backdrop-filter: blur(3px); }
.modal-panel {
  position: relative; width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px;
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 0 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* ------------------------------------------------------------------- auth */

body.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px; box-shadow: var(--shadow-1);
}
.auth-title { font-size: 21px; }
.auth-sub { color: var(--text-3); font-size: 13.5px; margin: 6px 0 20px; }
.auth-foot { margin-top: 18px; font-size: 13px; color: var(--text-3); text-align: center; display: flex; gap: 8px; justify-content: center; }
.auth-foot a { color: var(--text-2); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .split, .two-col { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .nav-toggle { display: inline-grid; order: -1; }
  .brand-name { display: none; }
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); z-index: 50;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-2);
  }
  .sidebar.is-open { transform: none; }
  .page { padding: 20px 16px 64px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .status-pill { min-width: 78px; }
}
