/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --blue-900: #0c1f3a;
  --blue-800: #112d52;
  --blue-700: #1a4070;
  --blue-600: #1f5296;
  --blue-500: #2563bf;
  --blue-400: #4a82d4;
  --blue-300: #7aaae6;
  --blue-200: #bcd4f4;
  --blue-100: #deeaf9;
  --blue-50:  #f0f6fd;

  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;

  --green-600: #16a34a;
  --green-100: #dcfce7;
  --green-700: #15803d;

  --red-600: #dc2626;
  --red-100: #fee2e2;
  --red-700: #b91c1c;

  --amber-600: #d97706;
  --amber-100: #fef3c7;

  --white: #ffffff;

  --sidebar-width: 236px;
  --header-height: 56px;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.04);

  --font: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;

  --transition: 140ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea {
  font-family: var(--font);
  font-size: 0.9rem;
}
h1,h2,h3,h4 { font-weight: 600; line-height: 1.25; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app { display: flex; min-height: 100vh; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: var(--sidebar-width);
  background: var(--blue-900);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
}
.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue-200);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.sidebar-property {
  font-size: 1rem;
  font-weight: 600;
  color: var(--white);
  margin-top: 4px;
  line-height: 1.3;
}

.sidebar-section {
  padding: 20px 12px 4px;
}
.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(255,255,255,.35);
  letter-spacing: .09em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: rgba(255,255,255,.65);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-size: 0.875rem;
  font-weight: 400;
  user-select: none;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: var(--white);
}
.nav-item.active {
  background: rgba(255,255,255,.11);
  color: var(--white);
  font-weight: 500;
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .75;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: rgba(255,255,255,.6);
  font-size: 0.8rem;
}
.sidebar-user-name { color: rgba(255,255,255,.85); font-weight: 500; }
.btn-logout {
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.5);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.78rem;
  margin-top: 6px;
  transition: var(--transition);
}
.btn-logout:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.8);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-900);
  flex: 1;
}
.topbar-actions { display: flex; gap: 10px; }

.content {
  padding: 28px;
  flex: 1;
  max-width: 1160px;
}

/* ============================================================
   COMPONENTS — BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--blue-600);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--blue-700); }
.btn-secondary {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-50); }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-success {
  background: var(--green-600);
  color: var(--white);
}
.btn-success:hover:not(:disabled) { background: var(--green-700); }
.btn-danger {
  background: var(--red-600);
  color: var(--white);
}

/* ============================================================
   COMPONENTS — CARDS
   ============================================================ */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-900);
}
.card-body { padding: 20px 22px; }

/* ============================================================
   COMPONENTS — STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--gray-500);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-value.blue { color: var(--blue-600); }
.stat-value.green { color: var(--green-700); }
.stat-value.red { color: var(--red-600); }
.stat-sub {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 5px;
}

/* ============================================================
   COMPONENTS — TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
.mono { font-family: var(--font-mono); font-size: 0.82rem; }

/* ============================================================
   COMPONENTS — BADGE
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-green { background: var(--green-100); color: var(--green-700); }
.badge-red { background: var(--red-100); color: var(--red-700); }
.badge-blue { background: var(--blue-100); color: var(--blue-700); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-amber { background: var(--amber-100); color: var(--amber-600); }

/* ============================================================
   COMPONENTS — FORMS
   ============================================================ */
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-700);
}
.form-input, .form-select, .form-textarea {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--gray-900);
  font-size: 0.875rem;
  transition: var(--transition);
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(37, 99, 191, .12);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.73rem; color: var(--gray-500); }

/* ============================================================
   COMPONENTS — MODAL
   ============================================================ */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 160ms ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 4px;
  transition: var(--transition);
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }
.modal-body { padding: 22px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================================================
   COMPONENTS — ALERT / NOTICE
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-warning { background: var(--amber-100); color: var(--amber-600); }
.alert-error   { background: var(--red-100); color: var(--red-700); }
.alert-success { background: var(--green-100); color: var(--green-700); }
.alert-info    { background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-200); }

/* ============================================================
   COMPONENTS — SECTION HEADER
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-900);
}
.section-desc {
  font-size: 0.82rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ============================================================
   PAGE: LOGIN
   ============================================================ */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--blue-900) 0%, var(--blue-800) 40%, var(--blue-700) 100%);
  padding: 20px;
}
#login-page[style*="display:none"] { display: none !important; }
.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--blue-900);
  border-radius: 10px;
  margin-bottom: 14px;
}
.login-logo-mark svg { color: var(--white); }
.login-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--gray-900);
  text-align: center;
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: var(--gray-500);
  font-size: 0.82rem;
  margin-bottom: 28px;
}

/* ============================================================
   PAYMENT STATUS ROW
   ============================================================ */
.payment-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}
.payment-row:last-child { border-bottom: none; }
.payment-unit {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--blue-50);
  border: 1px solid var(--blue-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--blue-700);
  flex-shrink: 0;
}
.payment-info { flex: 1; min-width: 0; }
.payment-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.payment-company {
  font-size: 0.72rem;
  color: var(--gray-400);
  margin-top: 1px;
}
.payment-amount {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-700);
  text-align: right;
  flex-shrink: 0;
}

/* ============================================================
   FUND CARDS
   ============================================================ */
.funds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.fund-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.fund-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--blue-500);
}
.fund-card.reserve::before { background: var(--green-600); }
.fund-name {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-500);
  margin-bottom: 10px;
}
.fund-balance {
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--gray-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.fund-account {
  font-size: 0.74rem;
  color: var(--gray-400);
  font-family: var(--font-mono);
  margin-top: 6px;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--gray-400);
  font-size: 0.85rem;
  gap: 10px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}
.empty-state-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}
.empty-state-desc { font-size: 0.82rem; }

/* ============================================================
   CALCULATOR SECTION
   ============================================================ */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.calc-category-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-400);
  margin: 16px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-100);
}
.calc-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.875rem;
}
.calc-result-row:last-child { border-bottom: none; }
.calc-result-unit { font-weight: 500; color: var(--gray-900); }
.calc-result-amount {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--blue-700);
  font-weight: 500;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  #sidebar { transform: translateX(-236px); width: 236px; transition: transform .25s ease; }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .content { padding: 16px; }
  .calc-grid { grid-template-columns: 1fr; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 16px; }
}

/* ============================================================
   HUSBOK — Húsfélagsbókin styles
   ============================================================ */
.husbok-toc {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 24px 28px;
  margin-bottom: 32px;
}
.husbok-toc h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin: 0 0 16px 0;
}
.husbok-toc ol {
  margin: 0;
  padding: 0 0 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 32px;
}
.husbok-toc ol li a {
  color: var(--blue-600);
  text-decoration: none;
  font-size: 14px;
}
.husbok-toc ol li a:hover { text-decoration: underline; }

.husbok-section {
  margin-bottom: 40px;
  scroll-margin-top: 80px;
}
.husbok-section h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
  border-bottom: 2px solid var(--blue-600);
  padding-bottom: 8px;
  margin: 0 0 20px 0;
}
.husbok-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
  margin: 24px 0 10px 0;
}
.husbok-section p, .husbok-section li {
  font-size: 14px;
  line-height: 1.7;
  color: var(--gray-600);
}
.husbok-section ul, .husbok-section ol {
  padding-left: 20px;
  margin: 8px 0 16px 0;
}
.husbok-section li { margin-bottom: 4px; }

.husbok-law-box {
  background: #eff6ff;
  border-left: 4px solid var(--blue-600);
  border-radius: 0 6px 6px 0;
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 13px;
  color: #1e40af;
}
.husbok-law-box strong { display: block; margin-bottom: 4px; font-size: 13px; }
.husbok-law-box a { color: #1d4ed8; }

.husbok-tip-box {
  background: #f0fdf4;
  border-left: 4px solid #22c55e;
  border-radius: 0 6px 6px 0;
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 13px;
  color: #166534;
}
.husbok-tip-box strong { display: block; margin-bottom: 4px; }

.husbok-warn-box {
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  border-radius: 0 6px 6px 0;
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 13px;
  color: #92400e;
}
.husbok-warn-box strong { display: block; margin-bottom: 4px; }

.husbok-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}
.husbok-table th {
  background: var(--gray-50);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--gray-200);
  color: var(--gray-900);
}
.husbok-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--gray-200);
  color: var(--gray-600);
  vertical-align: top;
}
.husbok-table tr:last-child td { border-bottom: none; }
.husbok-table tr:hover td { background: var(--gray-50); }

.husbok-back-top {
  display: inline-block;
  font-size: 12px;
  color: var(--gray-500);
  cursor: pointer;
  margin-top: 8px;
  text-decoration: none;
}
.husbok-back-top:hover { color: var(--blue-600); }

.husbok-feature-tag {
  display: inline-block;
  background: var(--blue-600);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
  letter-spacing: 0.03em;
}

@media (max-width: 640px) {
  .husbok-toc ol { grid-template-columns: 1fr; }
}
