:root {
  color-scheme: light;
  --ink: #0b2538;
  --muted: #45697e;
  --line: #9fd3ea;
  --panel: #f8fcff;
  --soft: #d4effb;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: #bae6fd;
  --warn: #a16207;
  --danger: #be123c;
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: linear-gradient(180deg, #e3f6ff 0%, var(--soft) 100%); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { background: var(--accent-strong); }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.icon { background: transparent; color: var(--ink); font-size: 24px; padding: 2px 8px; }

.hidden { display: none !important; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(3, 105, 161, .18);
}
.login-panel h1 { margin: 0 0 22px; font-size: 32px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .14);
  outline: 0;
}
textarea { min-height: 84px; resize: vertical; }
.login-panel label { margin-bottom: 14px; }
.login-panel button { width: 100%; margin-top: 4px; }
.error { color: var(--danger); min-height: 20px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.mobile-header, .menu-overlay { display: none; }
.sidebar {
  background: #e8f7ff;
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sidebar-close { display: none; }
.brand { font-size: 22px; font-weight: 800; }
nav { display: grid; gap: 6px; }
nav button {
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 6px;
}
nav button.active, nav button:hover { background: var(--accent); color: #ffffff; }
.content { min-width: 0; padding: 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h2 { margin: 0; font-size: 28px; }
.topbar p { margin: 5px 0 0; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat, .table-wrap, .calendar-grid, .empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.stat { padding: 16px; }
.stat strong { display: block; font-size: 28px; margin-top: 8px; }
.stat span, .muted { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.actions { white-space: nowrap; width: 1%; }
td.actions button { margin-right: 6px; padding: 7px 9px; }
.pill { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #bae6fd; color: #075985; font-size: 12px; }
.pill.due { background: #fee2e2; color: var(--danger); }
.pill.paid { background: #bfdbfe; color: #1e40af; }
.pill.warn { background: #fef9c3; color: var(--warn); }
.empty { padding: 28px; color: var(--muted); text-align: center; }

.invoice-header, .settings-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 16px;
}
.invoice-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
.invoice-header div {
  display: grid;
  gap: 4px;
}
.invoice-header div:last-child {
  text-align: right;
}
.invoice-header strong {
  font-size: 20px;
}
.invoice-header span {
  color: var(--muted);
}
.settings-panel dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 16px;
  margin: 0;
}
.settings-panel dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 5px;
}
.settings-panel dd {
  margin: 0;
  font-weight: 700;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.calendar-toolbar strong {
  text-align: center;
  font-size: 18px;
}
.calendar-toolbar button {
  min-height: 42px;
}
.calendar-toolbar button:last-child {
  justify-self: end;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); overflow: hidden; }
.day { min-height: 120px; padding: 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff; cursor: pointer; }
.day:hover { background: #f0f9ff; }
.day:nth-child(7n) { border-right: 0; }
.day strong { display: block; margin-bottom: 8px; }
.event {
  display: block;
  width: 100%;
  border-left: 3px solid var(--accent);
  padding: 6px 7px;
  background: var(--accent-soft);
  color: var(--ink);
  margin-bottom: 6px;
  border-radius: 4px;
  font-size: 13px;
  text-align: left;
}
.event:hover { background: #7dd3fc; color: #082f49; }
.event span { color: #075985; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 14px;
}
.detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fcff;
}
.detail-grid .full { grid-column: 1 / -1; }
.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}
.detail-grid strong { display: block; }
.detail-grid p { margin: 0; white-space: pre-wrap; }

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}
dialog::backdrop { background: rgba(8, 47, 73, .42); }
#modalForm header, #modalForm footer { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
#modalForm footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; gap: 10px; }
#modalTitle { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 18px; }
.form-grid label.full { grid-column: 1 / -1; }

@media (max-width: 900px) {
  .app-shell { display: block; min-height: 100vh; }
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 60px;
    padding: 10px 14px;
    background: rgba(248, 252, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  .mobile-header strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
  }
  .menu-button {
    min-height: 42px;
    padding: 10px 16px;
  }
  .menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    pointer-events: none;
    background: rgba(8, 47, 73, 0);
    opacity: 0;
    transition: opacity .18s ease, background .18s ease;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(340px, 88vw);
    padding: 16px;
    border-right: 1px solid var(--line);
    box-shadow: 18px 0 48px rgba(8, 47, 73, .18);
    transform: translateX(-105%);
    transition: transform .2s ease;
    overflow-y: auto;
  }
  .menu-open .sidebar { transform: translateX(0); }
  .menu-open .menu-overlay {
    pointer-events: auto;
    opacity: 1;
    background: rgba(8, 47, 73, .38);
  }
  .sidebar-close {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    background: var(--accent);
    color: #ffffff;
  }
  nav { grid-template-columns: 1fr; gap: 8px; }
  nav button {
    min-height: 46px;
    padding: 12px 14px;
    text-align: left;
  }
  #logoutButton { min-height: 46px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .topbar { align-items: stretch; flex-direction: column; }
  .invoice-header { flex-direction: column; }
  .invoice-header div:last-child { text-align: left; }
  .calendar-grid { grid-template-columns: 1fr; }
  .day { min-height: auto; border-right: 0; }
}

@media (max-width: 560px) {
  .content { padding: 14px; }
  .topbar h2 { font-size: 24px; }
  .topbar p { font-size: 14px; }
  table { min-width: 680px; }
  .calendar-toolbar { grid-template-columns: 1fr 1fr; }
  .calendar-toolbar strong { grid-column: 1 / -1; grid-row: 1; }
  .calendar-toolbar button { grid-row: 2; }
  .cards, .form-grid, .settings-panel dl, .detail-grid { grid-template-columns: 1fr; }
  dialog {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }
  .form-grid { gap: 12px; padding: 14px; }
}
