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

/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg:       #FFFFFF;
  --fg:       #000000;
  --muted:    #F2F2F2;
  --accent:   #FF3000;
  --border:   #000000;
  --surface:  #FFFFFF;
  --fg-muted: rgba(0, 0, 0, .45);

  --font: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', monospace;

  --border-thin:  2px;
  --border-thick: 4px;
}

/* ── Background Patterns ────────────────────────────────────────────────────── */
.swiss-grid {
  background-image:
    linear-gradient(rgba(0,0,0,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.03) 1px, transparent 1px);
  background-size: 24px 24px;
}
.swiss-dots {
  background-image: radial-gradient(rgba(0,0,0,.04) 1px, transparent 1px);
  background-size: 16px 16px;
}
.swiss-diagonal {
  background-image: repeating-linear-gradient(
    45deg, rgba(0,0,0,.02) 0, rgba(0,0,0,.02) 1px, transparent 1px, transparent 10px
  );
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
body {
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  align-items: center;
  background: var(--fg);
  border-bottom: var(--border-thick) solid var(--fg);
  color: var(--bg);
  display: flex;
  gap: 0;
  height: 56px;
  padding: 0 32px;
}

.header-wordmark {
  align-items: baseline;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-right: 24px;
}

header h1 {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.22em;
  line-height: 1;
  text-transform: uppercase;
}

.header-sub {
  color: rgba(255,255,255,.35);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.3em;
  margin-top: 3px;
  text-transform: uppercase;
}

.header-rule {
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
  height: 28px;
  margin-right: 24px;
  width: 1px;
}

#selected-project {
  background: var(--accent);
  color: var(--bg);
  display: none;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  margin-left: auto;
  padding: 6px 14px;
  text-transform: uppercase;
}
#selected-project:not(:empty) { display: inline-block; }

/* ── Nav ────────────────────────────────────────────────────────────────────── */
nav {
  background: var(--bg);
  border-bottom: var(--border-thick) solid var(--fg);
  display: flex;
}

nav button {
  background: var(--bg);
  border: none;
  border-right: 1px solid rgba(0,0,0,.1);
  color: var(--fg-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  height: 44px;
  letter-spacing: 0.25em;
  padding: 0 28px;
  position: relative;
  text-transform: uppercase;
  transition: color 150ms ease-out, background 150ms ease-out;
}
nav button:last-child { border-right: none; }

nav button::after {
  background: var(--accent);
  bottom: 0;
  content: '';
  height: 4px;
  left: 0;
  position: absolute;
  right: 0;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 150ms ease-out;
}

nav button:hover         { color: var(--fg); }
nav button.active        { color: var(--fg); font-weight: 900; }
nav button.active::after { transform: scaleX(1); }

/* ── Main ───────────────────────────────────────────────────────────────────── */
main {
  flex: 1;
  margin: 0 auto;
  max-width: 960px;
  padding: 40px 32px;
  width: 100%;
}

/* ── Pages ──────────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: var(--border-thin) solid var(--fg);
  margin-bottom: 24px;
  overflow: hidden;
  position: relative;
}

.card-header {
  align-items: center;
  background: var(--muted);
  border-bottom: var(--border-thin) solid var(--fg);
  display: flex;
  gap: 14px;
  padding: 12px 24px;
}
.card-header.swiss-dots {
  background-image: radial-gradient(rgba(0,0,0,.05) 1px, transparent 1px);
  background-size: 16px 16px;
}

.card-header h2 {
  color: var(--fg);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.section-num {
  color: var(--accent);
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.card-body { padding: 24px; }

/* Table sits flush in card — no card-body wrapper */
.card > table { border-top: none; }

/* ── Labels ─────────────────────────────────────────────────────────────────── */
label {
  color: var(--fg);
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  margin-bottom: 8px;
  margin-top: 20px;
  text-transform: uppercase;
}
label:first-child { margin-top: 0; }

/* ── Form Elements ──────────────────────────────────────────────────────────── */
select, textarea, input[type="text"], input[type="password"] {
  -webkit-appearance: none;
  background: var(--bg);
  border: var(--border-thin) solid var(--fg);
  border-radius: 0;
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  padding: 10px 14px;
  transition: border-color 150ms ease-out;
  width: 100%;
}
select:focus, textarea:focus, input:focus { border-color: var(--accent); }
select { cursor: pointer; }
textarea.mono { font-family: var(--mono); font-size: 12px; resize: vertical; }

/* ── Project + Refresh joined row ────────────────────────────────────────────── */
.project-select-row { display: flex; }
.project-select-row select { flex: 1; border-right: none; }
.project-select-row .btn-refresh {
  background: var(--muted);
  border: var(--border-thin) solid var(--fg);
  border-left: none;
  border-radius: 0;
  color: var(--fg);
  cursor: pointer;
  flex-shrink: 0;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  padding: 0 18px;
  text-transform: uppercase;
  transition: background 150ms ease-out, color 150ms ease-out;
  white-space: nowrap;
}
.project-select-row .btn-refresh:hover { background: var(--fg); color: var(--bg); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
button {
  border: var(--border-thin) solid var(--fg);
  border-radius: 0;
  cursor: pointer;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  padding: 13px 24px;
  text-transform: uppercase;
  transition: background 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}
button:disabled { cursor: not-allowed; opacity: .3; }

.btn-primary { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }

.btn-danger { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-danger:hover:not(:disabled) { background: var(--fg); border-color: var(--fg); }

.btn-ghost { background: var(--bg); border-color: var(--fg); color: var(--fg); }
.btn-ghost:hover:not(:disabled) { background: var(--fg); color: var(--bg); }

.btn-row { align-items: center; display: flex; gap: 12px; margin-top: 20px; }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  border-left: 4px solid var(--fg);
  font-size: 12px;
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 12px 16px;
}
.alert-error   { background: #fff5f3; border-left-color: var(--accent); color: #a00; }
.alert-success { background: #f0fff4; border-left-color: #005200;      color: #005200; }
.alert-warn    { background: #fffbe6; border-left-color: #7a5800;      color: #7a5800; }
.alert-info    { background: var(--muted); border-left-color: var(--fg); color: var(--fg); }

/* ── Tree Preview ────────────────────────────────────────────────────────────── */
.tree { font-size: 13px; line-height: 2.2; }
.tree-epic  {
  color: var(--fg);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.tree-story {
  border-left: 2px solid var(--fg);
  color: var(--fg);
  margin-left: 24px;
  padding-left: 14px;
}
.tree-task  {
  border-left: 2px solid rgba(0,0,0,.2);
  color: var(--fg-muted);
  margin-left: 48px;
  padding-left: 14px;
}
.tree-icon { color: var(--accent); margin-right: 10px; }

/* ── Editable Tree ───────────────────────────────────────────────────────────── */
.tree-node {
  border: var(--border-thin) solid var(--fg);
  margin-bottom: 6px;
  position: relative;
  transition: border-color 150ms ease-out;
}
.tree-node:hover { border-color: var(--accent); }

.tree-node-header {
  align-items: center;
  background: var(--muted);
  border-bottom: 1px solid rgba(0,0,0,.08);
  display: flex;
  gap: 10px;
  padding: 8px 12px;
}
.tree-node-header input {
  background: transparent;
  border: none;
  color: var(--fg);
  flex: 1;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  outline: none;
  padding: 0;
  text-transform: uppercase;
  width: 100%;
}
.tree-node-header input:focus {
  background: var(--bg);
  outline: 2px solid var(--accent);
  outline-offset: 0;
  padding: 0 4px;
}
.tree-node-body { background: var(--bg); padding: 12px; }
.tree-node-body textarea { font-size: 13px; min-height: 60px; text-transform: none; }
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.field-row label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; min-width: 60px; }
.field-row select { flex: 1; max-width: 220px; }

.node-epic  { border-left: 4px solid var(--fg);               margin-left: 0; }
.node-story { border-left: 4px solid rgba(0,0,0,.35);          margin-left: 24px; }
.node-task  { border-left: 2px solid rgba(0,0,0,.15);          margin-left: 48px; }

.node-type-label {
  background: var(--fg);
  color: var(--bg);
  flex-shrink: 0;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.22em;
  padding: 3px 7px;
  text-transform: uppercase;
}
.node-story .node-type-label { background: rgba(0,0,0,.5); }
.node-task  .node-type-label { background: rgba(0,0,0,.3); }

.btn-tiny {
  background: none;
  border: 1px solid transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 11px;
  height: 22px;
  line-height: 20px;
  padding: 0 6px;
  text-align: center;
  transition: all 150ms ease-out;
}
.btn-tiny:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.add-row { margin: 6px 0; }
.add-row button { font-size: 8px; padding: 8px 16px; }

/* ── Count badge ─────────────────────────────────────────────────────────────── */
.count-badge {
  background: var(--fg);
  color: var(--bg);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.2em;
  padding: 3px 8px;
  text-transform: uppercase;
}

/* ── Log Box ─────────────────────────────────────────────────────────────────── */
.log-box {
  background: var(--muted);
  border: var(--border-thin) solid var(--fg);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.85;
  max-height: 320px;
  overflow-y: auto;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-error   { color: var(--accent); }
.log-success { color: #005200; }
.log-warn    { color: #7a5800; }

/* ── History Table ───────────────────────────────────────────────────────────── */
table { border-collapse: collapse; font-size: 13px; width: 100%; }
thead { background: var(--fg); color: var(--bg); }
th {
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.3em;
  padding: 13px 20px;
  text-align: left;
  text-transform: uppercase;
}
td { border-bottom: 1px solid var(--muted); padding: 13px 20px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--muted); }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.2em;
  padding: 4px 9px;
  text-transform: uppercase;
}
.badge-success { background: #e6f4ea; color: #005200; }
.badge-failed  { background: #fff5f3; color: var(--accent); }
.badge-running { background: var(--muted); color: var(--fg); }

/* ── Progress Bar ─────────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--muted);
  border: var(--border-thin) solid var(--fg);
  height: 10px;
  margin: 16px 0;
  overflow: hidden;
}
.progress-bar {
  background: var(--accent);
  height: 100%;
  transition: width .3s ease-out;
}

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  animation: spin .6s linear infinite;
  border: 2px solid rgba(0,0,0,.12);
  border-radius: 50%;
  border-top-color: var(--accent);
  display: inline-block;
  height: 16px;
  vertical-align: middle;
  width: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  align-items: center;
  background: rgba(0,0,0,.75);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 100;
}
.modal-overlay.hidden { display: none !important; }

.modal-content {
  background: var(--bg);
  border: var(--border-thick) solid var(--fg);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  max-width: 95vw;
  overflow: hidden;
  width: 720px;
}
.modal-sm { width: 440px; }
.modal-header {
  align-items: center;
  background: var(--fg);
  color: var(--bg);
  display: flex;
  gap: 16px;
  padding: 14px 20px;
}
.modal-header h2 {
  flex: 1;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.modal-header button {
  background: none;
  border: 1px solid rgba(255,255,255,.25);
  color: var(--bg);
  font-size: 9px;
  letter-spacing: 0.15em;
  padding: 6px 12px;
}
.modal-header button:hover { background: var(--accent); border-color: var(--accent); }
.modal-body { flex: 1; overflow-y: auto; padding: 24px; }
.modal-body .log-box { margin-bottom: 16px; max-height: 200px; }
pre.log-box { max-height: 200px; }

/* ── Header User / Avatar Dropdown ───────────────────────────────────────────── */
.header-user { margin-left: auto; position: relative; }
.avatar-btn {
  align-items: center;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  letter-spacing: .02em;
  padding: 0;
  text-transform: uppercase;
  width: 34px;
}
.avatar-btn:hover { opacity: .85; }
.avatar-menu {
  background: var(--fg);
  border: var(--border-thin) solid var(--fg);
  color: var(--bg);
  display: none;
  min-width: 180px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 200;
}
.avatar-menu.open { display: block; }
.avatar-menu button {
  background: none;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,.1);
  color: var(--bg);
  cursor: pointer;
  display: block;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 12px 16px;
  text-align: left;
  text-transform: uppercase;
  width: 100%;
}
.avatar-menu button:last-child { border-bottom: none; }
.avatar-menu button:hover { background: var(--accent); }

/* ── User Management Modal ───────────────────────────────────────────────────── */
.user-modal-section { margin-bottom: 28px; }
.user-modal-section h3 { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; border-bottom: var(--border-thin) solid var(--border); padding-bottom: 8px; margin-bottom: 16px; }
.user-modal-section label { margin-top: 12px; }
.user-modal-section label:first-of-type { margin-top: 0; }

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--muted); }
.login-wrap { width: 100%; max-width: 400px; padding: 24px; }
.login-card { background: var(--surface); border: var(--border-thin) solid var(--border); padding: 40px; }
.login-header { border-bottom: var(--border-thin) solid var(--border); margin-bottom: 28px; padding-bottom: 20px; }
.login-header h1 { font-size: 22px; font-weight: 900; letter-spacing: -.02em; text-transform: uppercase; }
.login-card label { display: block; margin-bottom: 4px; margin-top: 16px; }
.login-card input { width: 100%; }

/* ── Danger button ───────────────────────────────────────────────────────────── */
.btn-danger { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
.btn-danger:hover { opacity: .85; }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt { margin-top: 20px; }
.muted { color: var(--fg-muted); font-size: 12px; }
.flex { align-items: center; display: flex; gap: 8px; }
