/* ── KI Project Delivery — Stylesheet ──────────────────────── */

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

:root {
  --purple-navy: #3B4270;
  --bright-navy: #3E76B8;
  --dark-sea-green: #83BD8E;
  --marigold: #E29F28;
  --vermillion: #D84220;
  --charcoal: #363C4C;
  --cultured: #F8F8F6;
  --off-white: #F9F9FA;
  --border: #ddd;
  --border-light: #eee;
  --border-row: #f0f0f0;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--charcoal);
  background: var(--off-white);
  line-height: 1.5;
}

/* ── Login screen ─────────────────────────── */
#login-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 1.5rem;
}
#login-screen h1 { color: var(--purple-navy); font-size: 1.5rem; }
#login-screen p { color: #888; }
#login-btn {
  padding: 10px 24px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--purple-navy); color: white; font-size: 1rem; font-weight: 500;
}
#login-btn:hover { opacity: 0.9; }
#login-error { color: var(--vermillion); display: none; }

/* ── Markdown content ─────────────────────── */
.field-content p { margin: 0.25em 0; }
.field-content p:first-child { margin-top: 0; }
.field-content p:last-child { margin-bottom: 0; }
.field-content ul, .field-content ol { margin: 0.25em 0; padding-left: 1.5em; }
.field-content li { margin: 0.15em 0; }
.field-content h1, .field-content h2, .field-content h3 { margin: 0.5em 0 0.25em; font-size: 1em; }
.field-content a { color: var(--bright-navy); }
.field-content code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
.field-content pre { background: #f0f0f0; padding: 0.5em; border-radius: 4px; overflow-x: auto; font-size: 0.85em; }
.field-content blockquote { border-left: 3px solid #ddd; padding-left: 0.75em; color: #666; margin: 0.25em 0; }

/* ── App shell ────────────────────────────── */
#app-shell { display: none; }

header {
  background: var(--purple-navy); color: white; padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between; height: 52px;
}
header h1 { font-size: 1rem; font-weight: 600; }
header nav { display: flex; gap: 1.5rem; align-items: center; }
header nav a {
  color: rgba(255,255,255,0.8); text-decoration: none; font-size: 0.9rem; font-weight: 500;
}
header nav a:hover, header nav a.active { color: white; }
#user-info {
  font-size: 0.8rem; color: rgba(255,255,255,0.7); display: flex; align-items: center; gap: 0.75rem;
}
#sign-out-btn {
  background: none; border: 1px solid rgba(255,255,255,0.3); color: rgba(255,255,255,0.8);
  padding: 3px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem;
}
#sign-out-btn:hover { border-color: white; color: white; }

#app-content {
  max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem;
}

/* ── Section cards ────────────────────────── */
.section-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.section-card-header {
  margin: 0;
  padding: 0.6rem 1rem;
  font-size: 0.95em;
  background: var(--cultured);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
}
.section-card-body {
  padding: 1rem;
}
details.section-card > summary::-webkit-details-marker { display: none; }
details.section-card > summary::marker { content: ''; }
details.section-card > summary::after {
  content: '▸'; margin-left: auto; transition: transform 0.15s;
}
details[open].section-card > summary::after {
  transform: rotate(90deg);
}

/* ── Buttons ──────────────────────────────── */
.btn {
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-family: inherit;
  line-height: 1.4;
}
.btn-primary {
  padding: 6px 16px;
  border: none;
  background: var(--purple-navy);
  color: white;
}
.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  padding: 6px 16px;
  border: 1px solid var(--border);
  background: white;
  color: #666;
}
.btn-secondary:hover { border-color: #bbb; }

.btn-danger {
  padding: 4px 10px;
  border: none;
  background: var(--vermillion);
  color: white;
}

.btn-sm {
  padding: 4px 12px;
}

.btn-xs {
  padding: 2px 10px;
  font-size: 0.75em;
}

.btn-ghost {
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--vermillion);
  font-size: 0.8em;
}

.btn-add {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 0.85em;
  color: #666;
}
.btn-add:hover { border-color: #bbb; }

/* ── Form controls ────────────────────────── */
.form-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  font-family: inherit;
}

.form-select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  font-family: inherit;
}
.form-select-full { width: 100%; }

.form-textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

.form-search {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
}

/* ── Field display ────────────────────────── */
.field {
  margin-bottom: 0.75rem;
}
.field-label {
  font-size: 0.75em;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Tables ───────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th {
  padding: 8px 12px;
  text-align: left;
}
.table thead tr {
  border-bottom: 2px solid var(--border-light);
}
.table-sm th,
.table-sm td {
  padding: 4px 8px;
}
.table-sm thead tr th {
  font-size: 0.8em;
  color: #888;
}
tbody tr:hover { background: #f4f4f2; }
.table-row {
  border-bottom: 1px solid var(--border-row);
}
.table td { padding: 8px 12px; }
.table-clickable { cursor: pointer; }

/* ── Status badges ────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 600;
}

/* ── Tab badge (count pill) ───────────────── */
.badge-count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #eee;
  font-size: 0.8em;
  margin-left: 4px;
}

/* ── Tabs ─────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: 1rem;
  gap: 0;
}
.tab {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  border: none;
  background: none;
  color: #888;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.tab.active, .tab--active {
  color: var(--purple-navy);
  border-bottom-color: var(--purple-navy);
}

/* ── Links ────────────────────────────────── */
.link { color: var(--bright-navy); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ── Layout utilities ─────────────────────── */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}
.flex-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.flex-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.flex-wrap { flex-wrap: wrap; }
.flex-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ── Text utilities ───────────────────────── */
.text-secondary { color: #888; }
.text-muted { color: #666; }
.text-error { color: var(--vermillion); }
.text-sm { font-size: 0.85em; }
.text-xs { font-size: 0.8em; }
.text-bold { font-weight: 500; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── Notes ────────────────────────────────── */
.note-entry {
  border-bottom: 1px solid var(--border-row);
  padding: 0.75rem 0;
}
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

/* ── Document category header ─────────────── */
.doc-category-title {
  margin: 0 0 0.5rem;
  font-size: 0.9em;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Responsive ───────────────────────────── */
@media (max-width: 768px) {
  header { flex-wrap: wrap; height: auto; padding: 0.75rem 1rem; gap: 0.5rem; }
  header nav { gap: 1rem; }
  #app-content { padding: 0 0.75rem; margin-top: 1rem; }

  .grid-2col {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Stack two-column grids (inline fallback) */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Scrollable tabs */
  .tabs, [style*="border-bottom:2px solid #eee"],
  [style*="border-bottom:1px solid #eee"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Tables: horizontal scroll wrapper */
  table { font-size: 0.85rem; display: block; overflow-x: auto; }
  thead, tbody, tr { min-width: 100%; }

  /* Dashboard header: stack title / controls */
  .flex-header,
  #app-content > div[style*="justify-content:space-between"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }

  /* Status section: allow wrapping */
  [style*="align-items:center"][style*="gap:1rem"] {
    flex-wrap: wrap;
  }

  /* Touch-friendly buttons and inputs */
  button, select, input[type="text"], input[type="date"], textarea {
    min-height: 44px;
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  /* Narrower section padding */
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1rem; }
}

/* Extra small (iPhone SE etc) */
@media (max-width: 400px) {
  header h1 { font-size: 0.85rem; }
  header nav { gap: 0.5rem; }
  header nav a { font-size: 0.8rem; }
  #user-info { font-size: 0.7rem; }
  #app-content { padding: 0 0.5rem; }
}
