:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-alt: #f9fafc;
  --border: #e6e8ee;
  --border-strong: #d7dae3;
  --text: #12141c;
  --text-muted: #676d7e;
  --text-faint: #9aa0b1;
  --brand: #0d1b2e;
  --brand-2: #16324f;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 6px 16px -4px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, 0.18);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

::selection { background: var(--accent-soft); color: var(--accent-hover); }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
}
button:hover { background: var(--surface-alt); border-color: #c7cbd6; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.15), 0 4px 12px -2px rgba(79, 70, 229, 0.35);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2), 0 8px 20px -4px rgba(79, 70, 229, 0.4); }

button.danger { color: var(--danger); background: transparent; border-color: transparent; }
button.danger:hover { background: var(--danger-bg); border-color: #fecaca; }

button.spinning { position: relative; color: transparent !important; pointer-events: none; }
button.spinning::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
button.primary:not(.spinning-dark).spinning::after { border-color: rgba(255,255,255,0.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
textarea { resize: vertical; min-height: 40px; font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:hover, textarea:hover, select:hover { border-color: #c2c6d2; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}
input[type="date"] { color-scheme: light; cursor: pointer; }
input[type="number"] { -moz-appearance: textfield; }

/* ---------------------------------------------------------------- login */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(79, 70, 229, 0.35), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(22, 50, 79, 0.5), transparent 45%),
    linear-gradient(160deg, var(--brand) 0%, var(--brand-2) 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 360px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.5s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.login-card h1 {
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.login-card p.subtitle {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 13px;
}
.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 16px 0 6px;
}
.login-card button.primary {
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  font-size: 14px;
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* -------------------------------------------------------------- shell --*/

#app-shell { min-height: 100vh; display: flex; flex-direction: column; }

header.topbar {
  background: var(--brand);
  color: white;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header.topbar .brand { display: flex; flex-direction: column; }
header.topbar .brand strong { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
header.topbar .brand span { font-size: 12px; color: #9fb3cc; }
header.topbar .user-info { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #cfd9e6; }
header.topbar .user-info .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: white; font-weight: 700; font-size: 11.5px;
  display: flex; align-items: center; justify-content: center;
}
header.topbar button { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.16); color: white; }
header.topbar button:hover { background: rgba(255,255,255,0.18); }

nav.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 28px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
nav.tabs button {
  border: none;
  background: transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 11px 18px;
  font-weight: 600;
  color: var(--text-muted);
  position: relative;
  box-shadow: none;
}
nav.tabs button:hover { color: var(--text); background: var(--surface-alt); }
nav.tabs button.active { color: var(--accent); }
nav.tabs button.active::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; bottom: -1px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

main { flex: 1; padding: 28px; max-width: 1120px; width: 100%; margin: 0 auto; animation: fadein 0.25s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
  max-width: 720px;
}

/* ------------------------------------------------------------- sections */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.section h3 {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--brand);
  font-weight: 700;
}
.section .note {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: -6px 0 16px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: #3d4254; }
.field.full { grid-column: 1 / -1; }

.file-field { display: flex; gap: 8px; align-items: center; }
.file-field input[type=file] {
  flex: 1;
  padding: 7px 10px;
  font-size: 12.5px;
}
.file-field .file-name { font-size: 12px; color: var(--success); font-weight: 600; white-space: nowrap; }

.money-field { display: flex; align-items: stretch; }
.money-field input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
  text-align: right;
}
.money-suffix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-left: none;
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 700;
}

/* --------------------------------------------------------------- sub-tabs */

.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.subtabs button {
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border-color: var(--border);
}
.subtabs button:hover { border-color: var(--border-strong); color: var(--text); }
.subtabs button.active { background: var(--brand); color: white; border-color: var(--brand); }

.subpanel { display: none; animation: fadein 0.2s var(--ease); }
.subpanel.active { display: block; }

/* --------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.search-box { position: relative; max-width: 320px; flex: 1; min-width: 200px; }
.search-box input { padding-left: 34px; }
.search-box::before {
  content: "";
  position: absolute;
  left: 11px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px;
  background: var(--text-faint);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center / contain no-repeat;
  pointer-events: none;
}

/* ---------------------------------------------------------------- table */

table.clients-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
table.clients-table th, table.clients-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
table.clients-table th { background: var(--surface-alt); color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
table.clients-table tbody tr { transition: background 0.12s var(--ease); }
table.clients-table tbody tr:hover { background: var(--accent-soft); cursor: pointer; }
table.clients-table tbody tr:last-child td { border-bottom: none; }
table.clients-table td.actions { white-space: nowrap; }
table.clients-table td.actions button { padding: 5px 11px; font-size: 12px; margin-right: 4px; }
.empty-row td { text-align: center; color: var(--text-faint); padding: 48px 20px; font-size: 13.5px; }

.tenant-cell { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.tenant-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #7c73f0);
  color: white; font-size: 11.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ----------------------------------------------------------------- toast */

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  white-space: pre-line;
  z-index: 1000;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0) scale(1); }
#toast.error { background: var(--danger); }
#toast.success { background: var(--success); }

/* --------------------------------------------------------------- footer */

.generate-bar {
  position: sticky;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.05);
}
.generate-bar .status { color: var(--text-muted); font-size: 13px; flex: 1; }
.generate-bar button.primary { padding: 10px 22px; font-size: 14px; min-width: 170px; }

.download-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.download-links a {
  font-size: 12.5px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-hover);
  text-decoration: none;
  font-weight: 600;
  transition: background 0.15s var(--ease);
}
.download-links a:hover { background: #dfe2fd; }

@media (max-width: 720px) {
  main { padding: 16px; }
  nav.tabs { padding: 8px 16px 0; overflow-x: auto; }
  header.topbar { padding: 14px 16px; }
}
