:root {
  --blue: #1e88e5; --blue-dark: #1565c0; --bg: #f4f6f9; --card: #fff; --text: #1f2933;
  --muted: #6b7280; --border: #e2e6ec; --green: #1f9d55; --red: #d64545; --amber: #c98a12;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.text-red { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 16px; font-weight: 600; text-align: center; }
.brand img { width: 90px; height: auto; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a { padding: 9px 12px; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidebar nav a:hover { background: #eef3fa; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; font-size: 13px; }
.content { flex: 1; min-width: 0; padding: 20px 24px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }

/* buttons */
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--blue); background: #fff; color: var(--blue);
  border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; text-align: center; }
.btn:hover { background: #eef6fe; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-whatsapp { background: var(--green); border-color: var(--green); color: #fff; }
.btn-whatsapp:hover { background: #18804a; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: #fdeeee; }
.btn-link { border: 0; background: none; padding: 4px 0; }
.btn-block { width: 100%; }

/* forms */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label, .trow label { font-weight: 600; font-size: 13px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd3dc; border-radius: 6px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8d9f8; border-color: var(--blue); }
input.invalid { border-color: var(--red); background: #fff6f6; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset.block { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
fieldset.block legend { font-weight: 600; padding: 0 6px; }
fieldset.block.spaced { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* tables */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--blue-dark);
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fafbfd; }
.table td { padding: 9px 12px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.table th.num { text-align: right; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: #f3f8fe; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
.filters { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.filters select { width: auto; }
.filters input { max-width: 280px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }

/* items table in the form */
.items-table td { padding: 6px; }
.items-table textarea { min-width: 260px; }
.items-table input { min-width: 70px; }
.items-table .n { width: 28px; color: var(--muted); }
.items-table .t { font-weight: 600; }
.item-actions { display: flex; gap: 10px; margin: 10px 0 16px; flex-wrap: wrap; align-items: center; }
.item-actions select { width: auto; min-width: 220px; }
.totals { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px; align-self: start; }
.trow { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.trow input { max-width: 140px; text-align: right; }
.trow.total { border-top: 1px solid var(--border); padding-top: 8px; font-weight: 700; font-size: 16px; margin-bottom: 0; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge-new { background: #fff4d6; color: var(--amber); }
.badge-invoiced, .badge-paid { background: #dff5e8; color: var(--green); }
.badge-unpaid, .badge-cancelled { background: #fdeaea; color: var(--red); }
.badge-partial { background: #fff1cf; color: var(--amber); }

/* document view page */
.view { display: flex; gap: 20px; align-items: flex-start; }
.view-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.doc-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; }
.actions { width: 220px; flex: none; display: flex; flex-direction: column; gap: 8px; }
.actions hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.statusbox { border: 1px solid var(--border); background: #fff; border-radius: 6px; text-align: center; padding: 10px; }
.status-big { font-size: 22px; font-weight: 600; text-transform: uppercase; }
.status-new, .status-partial { color: var(--amber); }
.status-invoiced, .status-paid { color: var(--green); }
.status-unpaid, .status-cancelled { color: var(--red); }
.panel h2 { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.booking-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 20px; margin: 0; }
.booking-list dt { color: var(--muted); }
.booking-list dd { margin: 0; overflow-wrap: anywhere; }
.booking-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.pay-summary { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.pay-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; margin-top: 12px; }
.pay-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap; margin-bottom: 14px; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-title { margin: 0; min-width: 150px; text-align: center; font-size: 17px; }
.cal-icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; font-size: 18px; line-height: 1;
  border-color: var(--border); color: var(--text); }
.cal-icon-btn:hover { border-color: var(--blue); }
.cal-today-btn { margin-left: 4px; padding: 4px 10px; border-color: transparent; font-size: 13px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-weekdays { margin-bottom: 8px; }
.cal-weekdays div { text-align: center; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cal-day { min-height: 98px; min-width: 0; padding: 6px; background: #fff; border: 1px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; gap: 4px; }
.cal-blank { min-width: 0; }
.cal-num { font-size: 12px; color: var(--muted); align-self: flex-start; }
.cal-today { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.cal-today .cal-num { color: var(--blue); font-weight: 700; }
.cal-chip { display: block; width: 100%; min-width: 0; margin: 0; padding: 3px 6px; border: 0; border-left: 3px solid var(--amber); border-radius: 4px;
  background: #fff1cf; color: var(--text); font: inherit; font-size: 12px; line-height: 1.35; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip:hover { filter: brightness(.96); }
.cal-chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.cal-chip-paid { border-left-color: var(--green); background: #dff5e8; }
.cal-list { display: none; }
.cal-list-day { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.cal-list-day h3 { margin: 0 0 2px; font-size: 14px; }
.cal-list-day .cal-chip { font-size: 13px; padding: 6px 8px; white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
.cal-legend { display: flex; gap: 8px 20px; flex-wrap: wrap; font-size: 13px; margin-left: auto; }
.cal-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; border-left: 3px solid var(--amber); background: #fff1cf; }
.cal-dot-paid { border-left-color: var(--green); background: #dff5e8; }
.cal-dialog { padding: 0; }
.cal-dialog-body { padding: 20px; }
.cal-dialog h2 { margin-top: 0; overflow-wrap: anywhere; }

/* dialog */
dialog { border: 0; border-radius: 10px; padding: 20px; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* toasts and banner */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 10px 14px; border-radius: 6px; color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 360px; }
.toast-ok { background: var(--green); }
.toast-error { background: var(--red); }
.banner-error { background: var(--red); color: #fff; text-align: center; padding: 8px 12px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 28px; width: min(380px, 92vw); text-align: center; }
.login-card form { text-align: left; margin-top: 16px; }
.login-logo { width: 120px; height: auto; }

/* public share page (kept in this file, not inline, so a strict Content-Security-Policy stays possible) */
.share-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--border); }
.share-bar strong { letter-spacing: .08em; color: var(--blue); font-size: 18px; }
.share-bar .btn[hidden] { display: none; }
.share-wrap { max-width: 900px; margin: 16px auto; padding: 0 12px; }
.share-msg { text-align: center; padding: 40px 12px; color: var(--muted); }

@media print {
  .no-print { display: none !important; }
}

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .brand { flex-direction: row; padding: 0; }
  .brand img { width: 40px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { border: 0; padding: 0; }
  .content { padding: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .view { flex-direction: column; }
  .actions { width: 100%; }
  .cal-weekdays, .cal-grid { display: none; }
  .cal-list { display: block; }
}
