:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --ink: #15232d;
  --muted: #6d7b86;
  --line: #d8e0e6;
  --accent: #7a5a3a;
  --accent-2: #936c45;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(60, 43, 30, .10);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { max-width: 1700px; margin: 0 auto; padding: 24px 28px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
h1 { margin: 2px 0 0; font-size: 30px; letter-spacing: -.04em; }
.eyebrow { color: var(--muted); font-weight: 700; letter-spacing: .14em; font-size: 11px; }
.topbar-actions, .toolbar-left, .toolbar-right, .action-row { display: flex; align-items: center; gap: 9px; }
.badge { display: inline-flex; align-items: center; min-height: 34px; padding: 0 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-muted { color: var(--muted); background: #e9edf1; }
.badge-ok { color: #085d49; background: #d9f2e9; }
.badge-bad { color: #8f1d17; background: #fde3df; }
.btn { border: 1px solid var(--line); color: var(--ink); background: var(--surface); min-height: 38px; border-radius: 9px; padding: 0 14px; font-weight: 650; box-shadow: 0 1px 1px rgba(0,0,0,.02); }
.btn:hover:not(:disabled) { border-color: #b9c3cd; transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { color: white; background: var(--accent); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-dark { color: white; background: #3a2d24; border-color: #3a2d24; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #efc2bd; background: #fff8f7; }
.hero-panel { display: flex; justify-content: space-between; gap: 30px; background: linear-gradient(135deg, #3b2d23 0%, #74583f 100%); color: white; padding: 30px 32px; border-radius: 22px; box-shadow: var(--shadow); }
.hero-panel h2 { margin: 4px 0 7px; font-size: 32px; letter-spacing: -.04em; }
.hero-panel p { margin: 0; color: #e8ddd3; }
.hero-kicker { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
.hero-metrics { display: grid; grid-template-columns: repeat(3, minmax(88px, 1fr)); gap: 10px; align-self: stretch; }
.metric { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 14px; padding: 13px 15px; min-width: 100px; }
.metric strong { display: block; font-size: 25px; }
.metric span { color: #dfd0c2; font-size: 11px; }
.tabs { display: flex; gap: 4px; margin: 22px 0 10px; overflow-x: auto; padding-bottom: 3px; }
.tab { border: 0; background: transparent; color: var(--muted); font-weight: 750; padding: 10px 13px; border-radius: 9px; white-space: nowrap; }
.tab:hover { background: #e9eff3; color: var(--ink); }
.tab.active { background: var(--surface); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.workspace { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.toolbar { min-height: 68px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.search-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.search-field input { width: min(360px, 32vw); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; }
.search-field input:focus, .field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,90,58,.13); }
.content-card { min-height: 420px; }
.table-wrap { overflow: auto; max-height: calc(100vh - 330px); }
.table-wrap.compact { max-height: 420px; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1900px; font-size: 12px; }
.compact table { min-width: 850px; }
th { position: sticky; top: 0; z-index: 2; background: #f7f9fa; color: #4f5d69; text-align: left; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; border-bottom: 1px solid var(--line); padding: 11px 10px; white-space: nowrap; }
td { border-bottom: 1px solid #edf0f2; padding: 9px 10px; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
tbody tr { background: white; }
tbody tr:hover { background: #faf7f3; }
tbody tr.selected { background: #f2e9df; outline: 1px solid #d1b99d; outline-offset: -1px; }
.status-pill { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #eef2f4; font-weight: 700; }
.folder-link { color: var(--accent); text-decoration: none; font-weight: 700; }
.empty-state { display: grid; place-items: center; align-content: center; text-align: center; min-height: 420px; padding: 40px; color: var(--muted); }
.empty-state h3 { color: var(--ink); margin-bottom: 4px; }
.notice { padding: 11px 16px; background: #f7f0e8; color: #67492e; border-bottom: 1px solid #ead9c7; font-size: 13px; }
.notice-error { background: #fff1ef; color: #8f1d17; border: 1px solid #f1cbc7; border-radius: 9px; margin-top: 16px; }
.hidden { display: none !important; }
.modal { border: 0; padding: 0; border-radius: 18px; width: min(96vw, 980px); box-shadow: 0 28px 90px rgba(0,0,0,.24); }
.modal::backdrop { background: rgba(14, 23, 30, .55); backdrop-filter: blur(2px); }
.modal-small { width: min(94vw, 470px); }
.modal-wide { width: min(96vw, 1050px); }
.modal-card { margin: 0; padding: 22px; background: var(--surface); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-header h3 { margin: 3px 0 0; font-size: 23px; }
.icon-btn { border: 0; background: #eef1f3; width: 34px; height: 34px; border-radius: 50%; font-size: 22px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field span { color: #50606d; font-weight: 750; font-size: 11px; }
.field input, .field select { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; min-height: 39px; background: white; outline: none; }
.field input[readonly] { background: #f5f7f8; color: #687782; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.section-label { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.modal-actions.split { justify-content: space-between; }
.help { color: var(--muted); font-size: 12px; line-height: 1.5; }
.identity-card { background: #f8f4ef; border: 1px solid #e7d9ca; padding: 15px; border-radius: 11px; display: flex; justify-content: space-between; gap: 20px; }
.identity-card span { color: var(--muted); }
.customer-form { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr 1.2fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.customer-form-actions { display: flex; gap: 7px; }
.muted { color: var(--muted); }
.audit-change { max-width: 520px; white-space: normal; line-height: 1.45; }

@media (max-width: 900px) {
  .app-shell { padding: 14px; }
  .topbar, .toolbar { align-items: stretch; flex-direction: column; }
  .topbar-actions, .toolbar-left { flex-wrap: wrap; }
  .hero-panel { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-3 { grid-column: span 2; }
  .customer-form { grid-template-columns: 1fr 1fr; }
  .search-field input { width: 100%; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
  .hero-metrics { grid-template-columns: repeat(2, 1fr); }
  .customer-form { grid-template-columns: 1fr; }
}

/* Users & access */
.users-page { padding: 16px; display: grid; gap: 16px; }
.user-add-card { display: grid; grid-template-columns: minmax(200px, 1.3fr) 220px 220px auto; gap: 10px; align-items: end; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafb; }
.user-add-card > div { display: flex; flex-direction: column; gap: 4px; }
.user-add-card > div span { color: var(--muted); font-size: 12px; }
.user-add-card input, .inline-select, .password-reset { width: 100%; min-height: 39px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: white; outline: none; }
.user-add-card input:focus, .inline-select:focus, .password-reset:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,90,58,.13); }
.users-table-wrap { max-height: calc(100vh - 420px); border: 1px solid var(--line); border-radius: 12px; }
.users-table { min-width: 860px; }
.user-actions { display: flex; gap: 8px; }
.access-label { display: inline-flex; min-height: 39px; align-items: center; font-weight: 700; color: var(--accent); }
.hero-panel p:empty { display: none; }

@media (max-width: 900px) {
  .hero-panel { padding: 24px; border-radius: 18px; }
  .hero-panel h2 { font-size: 30px; }
  .user-add-card { grid-template-columns: 1fr 1fr; }
  .users-table-wrap { max-height: calc(100vh - 360px); }
}

@media (max-width: 560px) {
  .app-shell { padding: 10px; }
  .topbar { gap: 12px; margin-bottom: 14px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { width: 100%; }
  .hero-panel { padding: 20px; }
  .hero-panel h2 { font-size: 27px; }
  .hero-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { padding: 10px; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar-left .btn { flex: 1 1 auto; }
  .search-field { width: 100%; flex-direction: column; align-items: stretch; }
  .table-wrap { max-height: calc(100vh - 300px); }
  .modal-card { padding: 18px; }
  .user-add-card { grid-template-columns: 1fr; }
  .user-add-card .btn { width: 100%; }
}


/* Blocking operation state */
body.is-busy { overflow: hidden; }
.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 24, 30, .52);
  backdrop-filter: blur(3px);
}
.busy-card {
  width: min(92vw, 420px);
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 28px 90px rgba(0,0,0,.28);
  padding: 28px;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
}
.busy-card strong { font-size: 20px; }
.busy-card span { color: var(--muted); line-height: 1.45; }
.busy-spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid #eadfd4;
  border-top-color: var(--accent);
  animation: busy-spin .8s linear infinite;
  margin-bottom: 6px;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .busy-spinner { animation-duration: 1.8s; }
}


/* Helsingin Hitsaus inspired test theme */
body {
  background:
    linear-gradient(180deg, #ffffff 0, #f5f7f8 210px, #f5f7f8 100%);
}
.topbar {
  padding-bottom: 10px;
  border-bottom: 1px solid #dfe5e9;
}
.eyebrow {
  color: #80654d;
}
.hero-panel {
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 18px 44px rgba(57, 39, 25, .14);
}
.metric {
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.16);
}
.tab.active {
  color: #6b4b31;
  box-shadow: 0 3px 10px rgba(74, 51, 34, .08);
}
.btn-primary {
  box-shadow: 0 4px 12px rgba(122,90,58,.18);
}
.workspace {
  border-color: #d7e0e6;
}
th {
  background: #f4f7f9;
  color: #5e5147;
}
.status-pill {
  background: #eef3f6;
  color: #5a493b;
}
.section-label,
.access-label,
.folder-link {
  color: #7a5a3a;
}

/* Warm HH brown refinement */
body {
  background:
    linear-gradient(180deg, #fffdfa 0, #f7f4f0 220px, #f5f3f0 100%);
}
.workspace,
.modal-card,
.busy-card {
  background: #fffdfa;
}
.tabs .tab:hover {
  background: #f1ebe5;
}
.tab.active {
  background: #fffaf5;
}
th {
  background: #f7f3ef;
}
tbody tr:hover {
  background: #fbf8f4;
}
