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

:root {
  /* Clark Construction brand — matches the work-tickets app */
  --navy:        #1B2B47;
  --navy-dark:   #111D36;
  --navy-mid:    #243660;
  --gold:        #C8A330;
  --gold-dark:   #A88A25;
  --gold-bg:     #FBF6E7;

  --primary:      var(--navy);
  --primary-dark: var(--navy-dark);

  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;

  --danger:  #C81E1E;
  --danger-bg: #FEF2F2;
  --success: #057A55;
  --success-bg: #ECFDF5;
  --warn:    #B45309;
  --warn-bg: #FFFBEB;
  --info-bg: #EFF6FF;
  --info:    #1E40AF;

  --radius:    6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
  --shadow:    0 2px 10px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #EEF0F4;
  color: var(--gray-800);
  min-height: 100vh;
  font-size: 15px;
}
.hidden { display: none !important; }

/* ── NAV ──────────────────────────────────────────────── */
nav {
  background: var(--navy-dark);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; height: 58px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  border-bottom: 3px solid var(--gold);
}
nav .brand { font-weight: 700; font-size: 1.05rem; letter-spacing: .6px; display: flex; align-items: center; gap: 10px; }
nav .brand::before {
  content: ''; width: 28px; height: 28px; background: var(--gold); border-radius: 4px; flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%231B2B47'%3E%3Cpath d='M4 3h11l5 5v13a1 1 0 01-1 1H5a1 1 0 01-1-1V4a1 1 0 011-1zm10 1.5V9h4.5L14 4.5zM7 12h10v1.6H7V12zm0 3.4h10V17H7v-1.6z'/%3E%3C/svg%3E");
  background-size: 19px; background-repeat: no-repeat; background-position: center;
}
.nav-right { display: flex; align-items: center; gap: 14px; }
.nav-user { font-size: .85rem; color: #C7CEDB; }
.nav-btn {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.3);
  padding: 6px 13px; border-radius: var(--radius); cursor: pointer; font-size: .82rem;
}
.nav-btn:hover { background: rgba(255,255,255,.1); }
.nav-health { font-size: .72rem; color: #9FB0C9; display: flex; gap: 10px; }
.nav-health span.bad { color: #FF9B9B; font-weight: 600; }

/* ── LOGIN ────────────────────────────────────────────── */
#login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, var(--navy) 0%, var(--navy-dark) 100%); padding: 20px;
}
.login-box { background: #fff; padding: 40px; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); width: 100%; max-width: 400px; }
.login-box h1 { font-size: 1.4rem; margin-bottom: 6px; color: var(--navy); }
.login-box .subtitle { color: var(--gray-500); font-size: .9rem; margin-bottom: 26px; }

/* ── LAYOUT ───────────────────────────────────────────── */
.container { max-width: 1340px; margin: 0 auto; padding: 24px 28px 60px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 1.18rem; font-weight: 650; }
.page-header p { color: var(--gray-500); font-size: .87rem; margin-top: 3px; }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--gray-200); margin-bottom: 24px; flex-wrap: wrap; }
.tab-btn {
  background: none; border: none; padding: 11px 19px; cursor: pointer;
  font-size: .9rem; font-weight: 550; color: var(--gray-500);
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--gold); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 22px 24px; border: 1px solid var(--gray-200); }
.card + .card { margin-top: 18px; }
.card-title { font-weight: 650; font-size: .98rem; margin-bottom: 16px; color: var(--navy); }
.card-sub { color: var(--gray-500); font-size: .86rem; margin: -10px 0 16px; line-height: 1.5; }

/* ── FORMS ────────────────────────────────────────────── */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-group .hint { font-weight: 400; color: var(--gray-400); }
input[type=text], input[type=password], input[type=date], input[type=number], textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: .9rem; font-family: inherit; background: #fff; color: var(--gray-800);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--navy-mid); box-shadow: 0 0 0 3px rgba(36,54,96,.12); }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }

.btn {
  padding: 9px 17px; border: none; border-radius: var(--radius); font-size: .88rem;
  font-weight: 600; cursor: pointer; font-family: inherit; display: inline-flex;
  align-items: center; gap: 7px; transition: background .12s, opacity .12s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--navy-dark); }
.btn-gold { background: var(--gold); color: var(--navy-dark); }
.btn-gold:hover:not(:disabled) { background: var(--gold-dark); color: #fff; }
.btn-outline { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: .79rem; }
.btn-full { width: 100%; justify-content: center; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 1.05rem; color: var(--gray-400); padding: 3px 7px; border-radius: 4px; }
.icon-btn:hover { background: var(--gray-100); color: var(--gray-700); }

/* ── ALERTS / BADGES ─────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: var(--radius); font-size: .87rem; margin-bottom: 15px; line-height: 1.5; }
.alert-error   { background: var(--danger-bg);  color: #9B1C1C; border: 1px solid #FCA5A5; }
.alert-success { background: var(--success-bg); color: #03543F; border: 1px solid #84E1BC; }
.alert-info    { background: var(--info-bg);    color: var(--info); border: 1px solid #BFDBFE; }
.alert-warn    { background: var(--warn-bg);    color: var(--warn); border: 1px solid #FDE68A; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 11px; font-size: .71rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge-proposal   { background: #E0E7FF; color: #3730A3; }
.badge-rfi        { background: #DBEAFE; color: #1E40AF; }
.badge-ticket     { background: var(--gold-bg); color: #8A6D13; }
.badge-rate_sheet { background: #F3E8FF; color: #6B21A8; }
.badge-co_template{ background: var(--gray-200); color: var(--gray-700); }
.badge-other      { background: var(--gray-100); color: var(--gray-500); }
.badge-high   { background: var(--danger-bg); color: #9B1C1C; }
.badge-medium { background: var(--warn-bg); color: var(--warn); }
.badge-low    { background: var(--gray-100); color: var(--gray-600); }
.badge-complete  { background: var(--success-bg); color: #03543F; }
.badge-failed    { background: var(--danger-bg); color: #9B1C1C; }
.badge-analyzing, .badge-building, .badge-checking, .badge-queued { background: var(--info-bg); color: var(--info); }
.badge-review { background: var(--gold-bg); color: #8A6D13; }

.conf-low    { color: var(--danger); font-weight: 600; }
.conf-medium { color: var(--warn); font-weight: 600; }
.conf-high   { color: var(--success); }

/* ── TABLES ───────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
thead th {
  background: var(--gray-50); text-align: left; padding: 10px 12px; font-weight: 650;
  font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200); white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-excluded { opacity: .42; }
.row-flag { background: var(--warn-bg) !important; }
.cell-note { display: block; color: var(--gray-500); font-size: .78rem; margin-top: 4px; line-height: 1.45; max-width: 460px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .83rem; }
td input[type=text], td input[type=number], td select { padding: 5px 7px; font-size: .84rem; }

/* ── UPLOAD ───────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--gray-300); border-radius: var(--radius-lg);
  padding: 34px 22px; text-align: center; cursor: pointer; background: var(--gray-50);
  transition: border-color .15s, background .15s;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--gold); background: var(--gold-bg); }
.upload-zone-text { font-size: .92rem; color: var(--gray-700); margin-top: 10px; font-weight: 550; }
.upload-link { color: var(--navy); text-decoration: underline; }
.upload-zone-hint { font-size: .79rem; color: var(--gray-400); margin-top: 5px; }
.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; }
.file-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 6px 10px; font-size: .83rem;
}
.file-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .size { color: var(--gray-400); font-size: .77rem; flex-shrink: 0; }

/* ── LOG ──────────────────────────────────────────────── */
.log {
  background: #0F172A; color: #CBD5E1; border-radius: var(--radius);
  padding: 13px 15px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem; line-height: 1.65; max-height: 280px; overflow-y: auto; white-space: pre-wrap;
}
.log .err { color: #FCA5A5; }
.log .warn { color: #FCD34D; }

.spinner {
  display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(27,43,71,.25); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── STATS ────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-card { background: #fff; border: 1px solid var(--gray-200); border-left: 3px solid var(--gold); border-radius: var(--radius); padding: 14px 16px; }
.stat-card .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-400); font-weight: 650; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: var(--navy); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-card .sub { font-size: .76rem; color: var(--gray-500); margin-top: 2px; }

.steps { display: flex; gap: 8px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; font-size: .82rem; }
.step { display: flex; align-items: center; gap: 7px; color: var(--gray-400); font-weight: 550; }
.step .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--gray-200); color: var(--gray-500); display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.step.active { color: var(--navy); }
.step.active .dot { background: var(--gold); color: var(--navy-dark); }
.step.done { color: var(--success); }
.step.done .dot { background: var(--success); color: #fff; }
.step-sep { color: var(--gray-300); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); }
.empty-state strong { display: block; color: var(--gray-700); margin-bottom: 5px; font-size: .95rem; }
.empty-state p { font-size: .86rem; }

/* ── MODAL ────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,29,54,.6); display: grid; place-items: center; z-index: 200; padding: 20px; }
.modal { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); max-width: 640px; width: 100%; max-height: 88vh; display: flex; flex-direction: column; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 1.05rem; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }

details.finding { border: 1px solid var(--gray-200); border-radius: var(--radius); margin-bottom: 7px; background: #fff; }
details.finding summary { padding: 9px 12px; cursor: pointer; font-size: .86rem; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
details.finding summary::-webkit-details-marker { display: none; }
details.finding[open] summary { border-bottom: 1px solid var(--gray-100); }
details.finding .body { padding: 11px 13px; font-size: .85rem; line-height: 1.6; color: var(--gray-600); }
details.finding .body dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin-bottom: 9px; }
details.finding .body dt { color: var(--gray-400); font-size: .78rem; }
details.finding .body dd { font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .container { padding: 18px 14px 50px; }
  nav { padding: 0 14px; }
  .nav-health { display: none; }
}
