/* MAERA Anon — App Stylesheet
   Design tokens from MAERA Brand Guide.
   Layout: fixed top header + sidebar nav + main content. */

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

:root {
  --navy:         #20334a;
  --orange:       #f75d12;
  --purple:       #4c2571;
  --sand:         #ffb936;
  --navy-light:   #8a9cb5;
  --orange-light: #ffa889;
  --purple-light: #b199c1;
  --grey:         #eeeeee;
  --white:        #ffffff;
  --text:         #000000;
  --font-h: 'Raleway', sans-serif;
  --font-b: 'Open Sans', sans-serif;
  --sidebar-w: 220px;
  --header-h: 60px;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(32,51,74,0.10);
}

body {
  font-family: var(--font-b);
  color: var(--text);
  background: var(--grey);
  line-height: 1.6;
  font-size: 0.9375rem;
}

h1,h2,h3,h4,h5,h6 { font-family: var(--font-h); line-height: 1.25; }

a { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */

.app-layout {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main";
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ── Header ── */

.app-header {
  grid-area: header;
  background: var(--white);
  border-bottom: 3px solid var(--orange);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(32,51,74,0.08);
}

.app-header .logo { height: 36px; flex-shrink: 0; }

.header-title {
  font-family: var(--font-h);
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.02em;
}

.header-spacer { flex: 1; }

.header-user {
  font-size: 0.8rem;
  color: var(--navy-light);
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-user strong { color: var(--navy); font-weight: 600; }

.btn-logout {
  font-family: var(--font-h);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--navy-light);
  border: 1px solid var(--navy-light);
  border-radius: var(--radius);
  padding: 4px 12px;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-logout:hover { color: var(--navy); border-color: var(--navy); text-decoration: none; }

/* ── Sidebar ── */

.app-sidebar {
  grid-area: sidebar;
  background: var(--navy);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 16px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--navy-light);
  margin-top: 16px;
}

.sidebar-section:first-child { margin-top: 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-family: var(--font-h);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy-light);
  text-decoration: none;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover { color: var(--white); text-decoration: none; }
.nav-link.active {
  color: var(--white);
  border-left-color: var(--orange);
  background: rgba(247,93,18,0.08);
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Main content ── */

.app-main {
  grid-area: main;
  padding: 32px;
  max-width: 960px;
}

.page-title {
  font-family: var(--font-h);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}
.page-title::before {
  content: '';
  display: block;
  width: 36px;
  height: 5px;
  background: var(--orange);
  margin-bottom: 10px;
}

.page-subtitle {
  color: var(--navy-light);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

/* ── Cards ── */

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-title {
  font-family: var(--font-h);
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-accent-orange { border-top: 4px solid var(--orange); }
.card-accent-navy   { border-top: 4px solid var(--navy); }
.card-accent-purple { border-top: 4px solid var(--purple); }
.card-accent-sand   { border-top: 4px solid var(--sand); }

/* ── Forms ── */

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 180px;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-h);
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="email"],
select,
textarea {
  font-family: var(--font-b);
  font-size: 0.9rem;
  padding: 9px 12px;
  border: 1.5px solid #d0d8e4;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(247,93,18,0.10);
}

textarea { resize: vertical; min-height: 120px; }

/* ── File Drop Zone ── */

.drop-zone {
  border: 2px dashed #c8d3de;
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #f8fafc;
  color: var(--navy-light);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--orange);
  background: rgba(247,93,18,0.04);
  color: var(--navy);
}

.drop-zone input[type="file"] {
  display: none;
}

.drop-zone-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  display: block;
}

.drop-zone-label {
  font-family: var(--font-h);
  font-size: 0.9rem;
  font-weight: 600;
}

/* ── Buttons ── */

.btn {
  font-family: var(--font-h);
  font-weight: 700;
  font-size: 0.875rem;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--orange); color: white; }
.btn-primary:hover { background: #d94e0a; transform: translateY(-1px); text-decoration: none; color: white; }

.btn-secondary { background: transparent; color: var(--navy); border: 2px solid var(--navy); }
.btn-secondary:hover { background: var(--navy); color: white; text-decoration: none; }

.btn-ghost-danger {
  background: transparent;
  color: #b91c1c;
  border: 1.5px solid #fca5a5;
  font-size: 0.8rem;
  padding: 4px 10px;
}
.btn-ghost-danger:hover { background: #fef2f2; }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--navy-light);
  transition: color 0.15s;
  display: inline-flex;
}
.btn-icon:hover { color: var(--orange); }

/* ── Mapping Table ── */

.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.mapping-table th {
  font-family: var(--font-h);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--navy-light);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--grey);
}

.mapping-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--grey);
  vertical-align: middle;
}

.mapping-table tr:last-child td { border-bottom: none; }
.mapping-table tr:hover td { background: #f8fafc; }

.mapping-group-header td {
  background: var(--grey);
  padding: 6px 12px;
  border-bottom: 1px solid #d0d8e4;
}
.mapping-group-header:hover td { background: var(--grey) !important; }

.token-badge {
  font-family: monospace;
  font-size: 0.8rem;
  background: var(--grey);
  color: var(--navy);
  padding: 2px 8px;
  border-radius: 3px;
  white-space: nowrap;
}

.type-badge {
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-h);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 3px;
}
.type-person   { background: rgba(76,37,113,0.12); color: var(--purple); }
.type-org      { background: rgba(247,93,18,0.12); color: #c04e0e; }
.type-email    { background: rgba(255,185,54,0.18); color: #7a5800; }
.type-location { background: rgba(32,51,74,0.10); color: var(--navy); }
.type-phone, .type-iban, .type-address, .type-id { background: var(--grey); color: var(--navy-light); }
.type-system { background: rgba(255,185,54,0.15); color: #7a5800; }

.aliases-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.alias-chip {
  font-size: 0.75rem;
  background: rgba(32,51,74,0.06);
  color: var(--navy);
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.alias-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--navy-light);
  font-size: 0.7rem;
  padding: 0;
  line-height: 1;
}
.alias-chip button:hover { color: #b91c1c; }

/* ── Entity Review ── */

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.entity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--white);
  border: 1.5px solid #d0d8e4;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.entity-item:has(input:checked) {
  border-color: var(--orange);
  background: rgba(247,93,18,0.04);
}

.entity-item input[type="checkbox"] {
  accent-color: var(--orange);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.entity-text {
  font-size: 0.875rem;
  color: var(--navy);
  font-weight: 500;
  flex: 1;
  word-break: break-word;
}

/* ── Project selector ── */

.project-selector {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.project-selector select {
  min-width: 200px;
  flex: 1;
  max-width: 320px;
}

/* ── Flash / Status ── */

.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.flash-ok  { background: rgba(34,197,94,0.1); color: #15803d; border: 1px solid rgba(34,197,94,0.3); }
.flash-err { background: rgba(239,68,68,0.1); color: #b91c1c; border: 1px solid rgba(239,68,68,0.3); }
.flash-info{ background: rgba(32,51,74,0.07); color: var(--navy); border: 1px solid rgba(32,51,74,0.15); }

.inline-status { font-size: 0.85rem; color: #15803d; }

/* ── Restore section ── */

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 700px) {
  .app-layout { grid-template-areas: "header" "main"; grid-template-columns: 1fr; }
  .app-sidebar { display: none; }
  .two-col { grid-template-columns: 1fr; }
  .app-main { padding: 20px 16px; }
}

/* ── Loading indicator (HTMX) ── */

.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ── Tabs ── */

.tab-bar {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--grey);
}

.tab-btn {
  font-family: var(--font-h);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 18px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  color: var(--navy-light);
  cursor: pointer;
  transition: all 0.15s;
  border-radius: var(--radius) var(--radius) 0 0;
}

.tab-btn:hover { color: var(--navy); background: rgba(32,51,74,0.04); }
.tab-btn.active { color: var(--orange); border-bottom-color: var(--orange); background: transparent; }

.tab-panel { animation: fadein 0.15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ── Login page ── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
}

.login-card {
  background: var(--white);
  border-radius: 10px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(32,51,74,0.25);
  text-align: center;
}

.login-card .logo { height: 44px; margin-bottom: 32px; }

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}

.login-card p {
  font-size: 0.875rem;
  color: var(--navy-light);
  margin-bottom: 32px;
  line-height: 1.5;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--orange);
  color: white;
  font-family: var(--font-h);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 13px 28px;
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
  justify-content: center;
}
.btn-google:hover { background: #d94e0a; transform: translateY(-1px); text-decoration: none; color: white; }

.login-error {
  margin-top: 16px;
  font-size: 0.8rem;
  color: #b91c1c;
}

/* ── Processing overlay ── */

.processing-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(32,51,74,0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}
.processing-overlay.active { display: flex; }

.processing-card {
  background: var(--white);
  border-radius: 10px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(32,51,74,0.25);
  max-width: 320px;
}

.processing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--grey);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

.processing-card h3 {
  font-family: var(--font-h);
  font-size: 1.1rem;
  color: var(--navy);
  margin-bottom: 8px;
}

.processing-card p {
  font-size: 0.85rem;
  color: var(--navy-light);
  line-height: 1.5;
}

/* ── Spinner (HTMX submit) ── */

.spinner {
  display: none;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
form.htmx-request .spinner { display: block; }
form.htmx-request .btn-label { display: none; }
