/* ===== Basic reset and page look ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f3f5f8;
  color: #1f2937;
}

.hidden { display: none !important; }

/* ===== Header ===== */
.app-header {
  background: #14365d;
  color: #ffffff;
  padding: 16px 28px;
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.app-header h1 { margin: 0; font-size: 22px; }
.app-subtitle { font-size: 13px; opacity: 0.8; }
.data-badge {
  margin-left: auto;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 12px;
  border-radius: 12px;
}
.data-badge.loaded { background: #15803d; }

/* ===== Tabs ===== */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: #ffffff;
  border-bottom: 1px solid #d5dbe3;
}
.tab-button {
  border: none;
  background: transparent;
  padding: 14px 20px;
  font-size: 15px;
  cursor: pointer;
  color: #4b5563;
  border-bottom: 3px solid transparent;
}
.tab-button:hover { background: #eef2f7; }
.tab-button.active {
  color: #14365d;
  font-weight: 600;
  border-bottom-color: #2f80ed;
}

/* ===== Content area ===== */
.app-main { padding: 24px 28px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

h2 { margin-top: 0; color: #14365d; }
h4 { margin: 20px 0 8px; color: #14365d; }

.placeholder-text { color: #6b7280; }

.card {
  background: #ffffff;
  border: 1px solid #d5dbe3;
  border-radius: 8px;
  padding: 18px 22px;
  margin-top: 16px;
  max-width: 760px;
}
.card.wide { max-width: 1000px; }
.card h3 { margin-top: 0; }

/* ===== Buttons ===== */
.primary-button {
  margin-top: 18px;
  background: #2f80ed;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 11px 22px;
  font-size: 15px;
  cursor: pointer;
}
.primary-button:hover { background: #1f6bd4; }
.primary-button:disabled {
  background: #aab4c3;
  cursor: not-allowed;
}

/* ===== File drop zone ===== */
.drop-zone {
  display: block;
  border: 2px dashed #8aa4c8;
  border-radius: 8px;
  background: #f7f9fc;
  padding: 36px 20px;
  text-align: center;
  color: #35557f;
  font-size: 16px;
  cursor: pointer;
}
.drop-zone:hover,
.drop-zone.drag-over {
  background: #e8f0fb;
  border-color: #2f80ed;
}

.status-line { min-height: 22px; margin: 12px 0 0; }
.status-info { color: #35557f; }

#sheetPicker { margin-top: 10px; }
#sheetPicker select { font-size: 14px; padding: 4px 8px; }

/* ===== Tables ===== */
.data-table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 14px;
}
.data-table th,
.data-table td {
  border: 1px solid #d5dbe3;
  padding: 8px 10px;
  text-align: left;
}
.data-table th { background: #eef2f7; }
.data-table td.num { text-align: right; white-space: nowrap; }

.small-table { font-size: 12px; width: auto; }
.small-table th,
.small-table td { padding: 5px 8px; white-space: nowrap; }

.narrow-table { width: auto; min-width: 380px; }

.table-scroll { overflow-x: auto; }

/* ===== Mapping wizard ===== */
.mapping-table select {
  width: 100%;
  min-width: 260px;
  font-size: 14px;
  padding: 5px 6px;
}
.mapping-table .field-hint { display: block; color: #6b7280; font-size: 12px; }
.mapping-table tr.row-error select { border: 2px solid #b91c1c; background: #fef2f2; }
.mapping-table tr.row-error td { background: #fffafa; }
.required-star { color: #b91c1c; font-weight: 700; }

.check-ok { color: #15803d; font-weight: 600; }
.check-error { color: #b91c1c; font-weight: 600; font-size: 13px; }

/* ===== Message boxes ===== */
.message-box {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 6px;
  background: #eef2f7;
  border: 1px solid #d5dbe3;
}
.message-box.ok      { background: #ecfdf3; border-color: #86d9a8; color: #14532d; }
.message-box.error   { background: #fef2f2; border-color: #f0a8a8; color: #7f1d1d; }
.message-box.warning { background: #fffbeb; border-color: #f2d27a; color: #78510a; }

/* ===== Statistic tiles ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.stat-tile {
  background: #f7f9fc;
  border: 1px solid #d5dbe3;
  border-radius: 8px;
  padding: 12px 14px;
}
.stat-tile .stat-label { font-size: 12px; color: #6b7280; }
.stat-tile .stat-value { font-size: 18px; font-weight: 600; color: #14365d; margin-top: 4px; }

/* ===== Dashboard ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.filter-bar select,
.section-control select { font-size: 14px; padding: 4px 8px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  max-width: 1100px;
}
.kpi-card {
  background: #ffffff;
  border: 1px solid #d5dbe3;
  border-left: 4px solid #2f80ed;
  border-radius: 8px;
  padding: 14px 16px;
}
.kpi-label { font-size: 13px; color: #6b7280; }
.kpi-value { font-size: 21px; font-weight: 600; color: #14365d; margin: 6px 0 2px; word-break: break-all; }
.kpi-sub { font-size: 12px; color: #9ca3af; }

.dash-card { max-width: 1100px; margin-top: 22px; }
.section-control { margin-bottom: 6px; }

.var-up   { color: #b45309; }   /* spend went up   */
.var-down { color: #15803d; }   /* spend went down */

.table-scroll.tall { max-height: 400px; overflow: auto; }
.spend-table { margin: 0; }
.spend-table th.num { text-align: right; }
.spend-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: 0 1px 0 #d5dbe3;
}
.spend-table tfoot td {
  position: sticky;
  bottom: 0;
  background: #eef2f7;
  font-weight: 600;
  box-shadow: 0 -1px 0 #d5dbe3;
}
.spend-table tr.clickable { cursor: pointer; }
.spend-table tr.clickable:hover td { background: #e8f0fb; }
.spend-table tr.clickable:focus { outline: 2px solid #2f80ed; outline-offset: -2px; }

.chart-box { position: relative; width: 100%; margin-top: 18px; }

.back-button,
.link-button {
  background: none;
  border: none;
  color: #2f80ed;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
}
.back-button { margin-bottom: 10px; }
.back-button:hover,
.link-button:hover { text-decoration: underline; }
.link-button { margin-left: 10px; }

/* ===== Supplier Search ===== */
.search-card { max-width: 1100px; }
.search-label { display: block; font-weight: 600; margin-bottom: 8px; color: #14365d; }
.search-input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 2px solid #8aa4c8;
  border-radius: 6px;
}
.search-input:focus { outline: none; border-color: #2f80ed; }
.search-card .filter-bar { margin: 12px 0 0; }

.match-list { list-style: none; margin: 0; padding: 0; }
.match-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 1px solid #d5dbe3;
  border-top: none;
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
}
.match-list li:first-child .match-item { border-top: 1px solid #d5dbe3; border-radius: 6px 6px 0 0; }
.match-list li:last-child .match-item { border-radius: 0 0 6px 6px; }
.match-item:hover { background: #e8f0fb; }
.match-item.selected { background: #dbe9fc; font-weight: 600; }
.match-spend { color: #6b7280; white-space: nowrap; font-weight: 400; }

.supplier-title { margin: 24px 0 8px; font-size: 24px; }
.block-title { margin: 18px 0 10px; color: #14365d; }

/* ===== Export buttons (Phase 6) ===== */
.export-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
}
.export-button {
  background: #ffffff;
  color: #14365d;
  border: 1px solid #8aa4c8;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 14px;
  cursor: pointer;
}
.export-button:hover { background: #e8f0fb; }
.export-button:disabled { color: #9ca3af; border-color: #d5dbe3; cursor: wait; }
.export-status { font-size: 13px; }

/* ===== Login screen and user bar (online version) ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #f3f5f8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 20px;
}
.auth-box {
  background: #ffffff;
  border: 1px solid #d5dbe3;
  border-radius: 10px;
  padding: 28px 32px;
  width: 100%;
  max-width: 420px;
}
.auth-box h1 { margin: 0 0 6px; font-size: 22px; color: #14365d; }
.auth-box h2 { margin: 0 0 6px; font-size: 18px; }
.auth-sub { color: #6b7280; font-size: 13px; margin: 0 0 16px; }
.auth-field { display: block; margin: 12px 0; font-size: 14px; }
.auth-field input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font-size: 15px;
  border: 1px solid #b8c2d0;
  border-radius: 6px;
}
.auth-remember { display: block; margin: 10px 0 4px; font-size: 14px; color: #4b5563; }
.auth-button { width: 100%; margin-top: 14px; }
.auth-message { margin-top: 14px; font-size: 14px; min-height: 20px; }
.auth-message.error { color: #b91c1c; }
.auth-message.info { color: #35557f; }

.user-bar { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-bar-button {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}
.user-bar-button:hover { background: rgba(255, 255, 255, 0.28); }

/* ===== Admin tab ===== */
.admin-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.admin-form label { display: flex; flex-direction: column; font-size: 13px; color: #4b5563; gap: 4px; }
.admin-form input, .admin-form select { font-size: 14px; padding: 6px 8px; min-width: 200px; }
.admin-form .primary-button { margin-top: 0; }
#tab-admin .user-bar-button {
  background: #ffffff;
  color: #14365d;
  border: 1px solid #8aa4c8;
}
#tab-admin .user-bar-button:hover { background: #e8f0fb; }
#tab-admin .user-bar-button:disabled { color: #9ca3af; border-color: #d5dbe3; cursor: not-allowed; }
#tab-admin .danger-button { color: #b91c1c; border-color: #e0a3a3; }
.admin-actions { white-space: nowrap; }
.admin-actions button { margin-right: 6px; }
.note-input { width: 180px; font-size: 13px; padding: 4px 6px; }
.valid-input, .role-select { font-size: 13px; padding: 4px 6px; }
.status-active { color: #15803d; font-weight: 600; }
.status-inactive, .status-expired { color: #b91c1c; font-weight: 600; }
.credentials-box {
  margin-top: 14px;
  padding: 12px 16px;
  background: #fffbeb;
  border: 1px solid #f2d27a;
  border-radius: 6px;
}
.credentials-line { margin-top: 6px; }
.credentials-box code { background: #ffffff; padding: 2px 8px; border-radius: 4px; border: 1px solid #e5e7eb; }
.credentials-password { font-size: 16px; letter-spacing: 0.5px; margin-right: 8px; }

/* ===== Status colors ===== */
.status-ok   { color: #15803d; font-weight: 600; }
.status-fail { color: #b91c1c; font-weight: 600; }

.test-line { margin-top: 14px; }
.hint { color: #6b7280; font-size: 13px; }

code {
  background: #eef2f7;
  padding: 1px 6px;
  border-radius: 4px;
}
