:root {
  --navy-950: #08172c;
  --navy-900: #0b1f3a;
  --navy-800: #14345d;
  --navy-700: #214b7d;
  --gold-600: #a97820;
  --gold-500: #c59a3d;
  --gold-200: #ead7aa;
  --cream: #f7f4ec;
  --surface: #ffffff;
  --surface-alt: #f4f6f8;
  --text: #172033;
  --muted: #667085;
  --border: #d8dee8;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #067647;
  --success-soft: #dcfae6;
  --shadow: 0 8px 24px rgba(8, 23, 44, .08);
  --radius: 12px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { color: var(--navy-900); font-family: Georgia, "Times New Roman", serif; line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin-bottom: .6rem; }
h2 { font-size: 1.5rem; margin-bottom: 0; }
h3 { font-size: 1.1rem; margin-bottom: 0; }

a { color: var(--navy-700); }

[hidden] { display: none !important; }

.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy-950), var(--navy-800));
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 470px);
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
  padding: clamp(24px, 6vw, 44px);
}

.installer-shell .auth-card { width: min(100%, 820px); }

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gold-500);
  color: var(--navy-950);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  margin-bottom: 18px;
}

.brand-mark-small { width: 42px; height: 42px; margin: 0; flex: 0 0 auto; }

.eyebrow {
  color: var(--gold-600);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.muted { color: var(--muted); }
.security-note { color: var(--muted); font-size: .78rem; margin: 14px 0 0; }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-two { grid-column: 1 / -1; }

label { display: grid; gap: 6px; color: var(--navy-900); font-size: .86rem; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  font-weight: 400;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-700); box-shadow: 0 0 0 3px rgba(33,75,125,.14); }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
legend { color: var(--navy-900); font-family: Georgia, "Times New Roman", serif; font-weight: 700; padding: 0 8px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 13px;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.button-primary { background: var(--navy-900); color: #fff; }
.button-primary:hover { background: var(--navy-800); }
.button-gold { background: var(--gold-500); color: var(--navy-950); }
.button-gold:hover { background: var(--gold-200); }
.button-secondary { background: var(--surface); border-color: var(--border); color: var(--navy-900); }
.button-secondary:hover, .button-ghost:hover { background: var(--surface-alt); }
.button-ghost { background: transparent; color: var(--navy-800); }
.button-danger-outline { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.button-full { width: 100%; }
.button:focus-visible, .tab:focus-visible, .text-button:focus-visible { outline: 3px solid var(--gold-500); outline-offset: 2px; }

.alert, .notice { border-radius: 8px; padding: 11px 13px; }
.alert-error, .notice.is-error { background: var(--danger-soft); color: var(--danger); }
.alert-success, .notice.is-success { background: var(--success-soft); color: var(--success); }

.app-shell { width: min(100%, 1480px); margin: 0 auto; padding: 18px; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--navy-900);
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.brand-block, .header-actions, .section-heading, .form-actions, .row-actions, .inline-form, .user-chip {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; min-width: 220px; }
.brand-block .eyebrow { color: var(--gold-200); }
.app-title { font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; }
.header-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.user-chip { min-height: 36px; padding: 6px 10px; color: var(--gold-200); font-size: .85rem; }
.app-header .button-secondary { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.22); color: #fff; }
.app-header .button-ghost { color: #fff; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 16px 2px;
}

.tab {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--navy-900);
  padding: 8px 13px;
  font-weight: 700;
}

.tab.is-active { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.notice { margin-bottom: 14px; background: var(--surface); border: 1px solid var(--border); }

main, .view, .stack { display: grid; gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.edit-panel { margin-bottom: 16px; border-top: 4px solid var(--gold-500); }
.section-heading { justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-heading p:last-child { margin-bottom: 0; }
.form-actions { justify-content: flex-end; gap: 10px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.metric-label { color: var(--muted); font-size: .8rem; }
.metric-value { color: var(--navy-900); font-family: Georgia, "Times New Roman", serif; font-size: 1.7rem; margin: 3px 0; }
.metric-context { color: var(--muted); font-size: .78rem; }

.two-column, .partner-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.pipeline-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.filter-grid { display: grid; grid-template-columns: 2fr repeat(3, minmax(130px, 1fr)); gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

.text-button { border: 0; background: transparent; color: var(--navy-700); font-weight: 700; padding: 4px; }
.text-button:hover { text-decoration: underline; }

.list, .contact-list, .task-list, .activity-list { border-top: 1px solid var(--border); }
.list-row, .mini-record, .task-row, .activity-row { border-bottom: 1px solid var(--border); padding: 11px 0; }
.list-row:last-child, .mini-record:last-child, .task-row:last-child, .activity-row:last-child { border-bottom: 0; }
.list-row, .record-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.primary-text { color: var(--navy-900); font-weight: 750; }
.secondary-text { color: var(--muted); font-size: .78rem; }

.stage-breakdown { display: grid; gap: 7px; }
.bar-track { appearance: none; width: 100%; height: 8px; overflow: hidden; border: 0; border-radius: 999px; background: #e7ebf0; }
.bar-track::-webkit-progress-bar { background: #e7ebf0; border-radius: 999px; }
.bar-track::-webkit-progress-value { background: var(--gold-500); border-radius: 999px; }
.bar-track::-moz-progress-bar { background: var(--gold-500); border-radius: 999px; }

.contact-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.6fr) minmax(115px, .9fr) minmax(90px, .7fr) minmax(100px, .8fr) minmax(160px, 1.2fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 12px 4px;
}
.contact-header { color: var(--muted); font-size: .75rem; font-weight: 700; padding-top: 8px; }
.contact-cell { min-width: 0; overflow-wrap: anywhere; }
.row-actions { justify-content: flex-end; flex-wrap: wrap; gap: 5px; }
.row-actions .button { min-height: 34px; padding: 6px 9px; font-size: .78rem; }

.badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; background: #e9eef5; color: var(--navy-800); padding: 4px 8px; font-size: .72rem; font-weight: 750; }
.badge-gold { background: #f7ebce; color: #78520f; }
.badge-alert { background: var(--danger-soft); color: var(--danger); }

.stage-card, .partner-card { display: grid; gap: 12px; }
.stage-card .mini-record { display: grid; gap: 8px; }
.stage-card select { padding: 7px 9px; }
.partner-stats { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.partner-stat { background: var(--surface-alt); border-radius: 8px; padding: 10px; }

.task-row { display: grid; grid-template-columns: minmax(170px,1.3fr) minmax(180px,1fr) auto; align-items: center; gap: 14px; }
.activity-row { display: grid; grid-template-columns: minmax(150px,.8fr) minmax(220px,1.5fr) minmax(130px,.7fr); gap: 14px; }
.activity-type { color: var(--gold-600); font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }

.empty { border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); padding: 20px; text-align: center; }
.settings-form { width: min(100%, 620px); }
.app-footer { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .75rem; padding: 18px 4px 6px; }

@media (max-width: 1080px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contact-header { display: none; }
  .contact-row { grid-template-columns: repeat(2, minmax(0,1fr)); align-items: start; }
  .contact-cell::before { content: attr(data-label); display: block; color: var(--muted); font-size: .7rem; margin-bottom: 3px; }
  .contact-primary::before, .contact-actions::before { display: none; }
  .contact-primary, .contact-actions { grid-column: 1 / -1; }
  .row-actions { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; }
  .app-header { border-radius: 10px; }
  .brand-block { min-width: 0; }
  .header-actions { width: 100%; }
  .header-actions .button, .header-actions .inline-form { flex: 1 1 auto; }
  .header-actions .inline-form .button { width: 100%; }
  .two-column, .partner-grid, .pipeline-grid, .form-grid, .filter-grid, .task-row, .activity-row { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .panel { padding: 14px; }
  .activity-row { gap: 5px; }
}

@media (max-width: 440px) {
  .metric-grid, .contact-row, .partner-stats { grid-template-columns: 1fr; }
  .contact-primary, .contact-actions { grid-column: auto; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 10px; }
  .tab { flex: 0 0 auto; }
  .app-footer { flex-direction: column; }
}
