@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,600;8..60,700&display=swap');

:root {
  --navy: #0A1F44;
  --navy-dark: #061428;
  --navy-mid: #123056;
  --teal: #0d7377;
  --teal-light: #14919b;
  --white: #fff;
  --off: #f5f7fa;
  --border: #e2e8f0;
  --muted: #64748b;
  --text: #1e293b;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(10,31,68,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--off);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
h1,h2,h3 { font-family: 'Source Serif 4', Georgia, serif; color: var(--navy); }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--navy-dark), var(--navy-mid));
  padding: 24px;
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
.login-card .logo { height: 64px; margin: 0 auto 20px; display: block; }
.login-card h1 { text-align: center; font-size: 1.5rem; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 28px; }
.login-card label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.login-card input, .login-card select {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; margin-bottom: 16px; font-size: 15px; font-family: inherit;
}
.login-card input:focus, .login-card select:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(10,31,68,.12);
}
.demo-hint {
  background: var(--off); border-radius: 8px; padding: 12px 14px;
  font-size: .8rem; color: var(--muted); margin-top: 16px; line-height: 1.55;
}
.demo-hint strong { color: var(--navy); }

/* App shell */
.app { display: none; min-height: 100vh; }
.app.active { display: flex; flex-direction: column; }

.topbar {
  background: var(--navy-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar .brand img { height: 40px; }
.topbar .brand span { font-weight: 600; font-size: .95rem; }
.topbar .meta { display: flex; align-items: center; gap: 12px; font-size: .85rem; color: rgba(255,255,255,.8); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 100px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge-master { background: #c9a227; color: #1a1a1a; }
.badge-staff { background: var(--teal); color: #fff; }
.badge-client { background: #64748b; color: #fff; }
.badge-closed { background: var(--danger); color: #fff; }
.badge-open { background: var(--success); color: #fff; }

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 230px; background: var(--white); border-right: 1px solid var(--border);
  padding: 16px 12px; flex-shrink: 0; overflow-y: auto;
}
.sidebar button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 14px; border: none; background: transparent;
  border-radius: 8px; font-size: .9rem; font-weight: 500; color: var(--text);
  cursor: pointer; text-align: left; font-family: inherit; margin-bottom: 2px;
}
.sidebar button:hover { background: var(--off); }
.sidebar button.active { background: var(--navy); color: #fff; }
.sidebar .nav-label {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); padding: 14px 14px 6px;
}

.main { flex: 1; padding: 24px; overflow-y: auto; }
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 22px;
}
.page-header h2 { font-size: 1.55rem; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: none; font-weight: 600;
  font-size: .88rem; cursor: pointer; font-family: inherit; transition: .2s;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-mid); }
.btn-teal { background: var(--teal); color: #fff; }
.btn-outline { background: #fff; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 1.45rem; font-weight: 700; color: var(--navy); margin-top: 4px; font-family: 'Source Serif 4', serif; }
.stat-card .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 20px;
}
.panel-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.panel-head h3 { font-size: 1.05rem; font-family: 'Inter', sans-serif; font-weight: 600; }
.panel-body { padding: 16px 18px; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--off); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbfc; }
.total-row td { font-weight: 700; background: var(--off); border-top: 2px solid var(--navy); }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: .9rem; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--navy);
}

.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(6,20,40,.55);
  z-index: 1000; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 1.15rem; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--muted); }

.alert {
  padding: 12px 14px; border-radius: 8px; font-size: .88rem; margin-bottom: 14px;
}
.alert-info { background: #e8f4fc; color: #0c4a6e; }
.alert-success { background: #ecfdf5; color: #065f46; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-danger { background: #fef2f2; color: #991b1b; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.period-select { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period-select select, .period-select input { padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); }

.entry-lines { margin-top: 8px; }
.entry-line {
  display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: end;
}
@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; display: flex; flex-wrap: wrap; gap: 4px; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar .nav-label { width: 100%; }
  .sidebar button { width: auto; flex: 1 1 auto; }
  .entry-line { grid-template-columns: 1fr 1fr; }
}

.statement-title { text-align: center; margin-bottom: 16px; }
.statement-title h3 { margin-bottom: 4px; }
.statement-title p { color: var(--muted); font-size: .9rem; }
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .page-header .actions, .btn { display: none !important; }
  .main { padding: 0; }
  .print-only { display: block; }
}

.user-table .role-tag { font-size: .75rem; font-weight: 600; }

/* Logo polish */
.login-card .logo {
  height: 72px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  margin: 0 auto 18px;
  display: block;
}
.topbar .brand img {
  height: 44px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  display: block;
}
.topbar .brand {
  gap: 14px;
}
.topbar .company-switch {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: .85rem;
  font-family: inherit;
  max-width: 220px;
}
.topbar .company-switch option { color: #111; }
.topbar .company-label {
  font-weight: 600;
  font-size: .9rem;
  color: #fff;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: .9rem;
  cursor: pointer;
}
.ok { color: var(--success); font-weight: 600; }
.muted { color: var(--muted); }
.bad { color: var(--danger); font-weight: 600; }
.balance-msg { margin-top: 12px; font-size: .85rem; }
.balance-msg.ok { color: var(--success); }
.balance-msg.bad { color: var(--danger); }

/* Clients never see edit chrome */
body.role-client .edit-only { display: none !important; }

.icon-svg {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: -3px;
  margin-right: 2px;
}

.print-header {
  display: none;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--navy);
}
.print-header img {
  height: 48px;
  width: auto;
  object-fit: contain;
}

@media print {
  body { background: #fff !important; }
  .login-screen, .topbar, .sidebar, .page-header .actions,
  .period-select button, .btn, .modal-overlay { display: none !important; }
  .layout { display: block !important; }
  .main { padding: 0 !important; }
  .page { display: none !important; }
  .page.active { display: block !important; }
  .panel { box-shadow: none !important; border: none !important; }
  .print-header { display: flex !important; }
  .report-sheet { break-inside: avoid; }
}
