:root {
  --bg: #f4f6f5; --panel: #ffffff; --ink: #1d2a27; --muted: #6a7a76; --line: #dfe5e3;
  --brand: #146356; --brand-ink: #ffffff; --brand-soft: #e3f1ee;
  --danger: #c0392b; --warn: #b7791f; --ok: #2f855a;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 200px; background: #10302a; color: #cfe3de; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow: auto; }
.sidebar { display: flex; flex-direction: column; }
#nav { flex: 1; }
#nav a[hidden] { display: none; }
.user-box { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.user-box button { background: transparent; color: #cfe3de; border-color: rgba(255,255,255,.25); }
.user-box button:hover { border-color: #fff; color: #fff; }
#auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; }
.brand { display: flex; gap: 8px; align-items: center; padding: 16px; font-weight: 600; color: #fff; font-size: 15px; }
.brand-mark { background: var(--brand); width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; }
#nav a { display: block; padding: 9px 16px; color: inherit; text-decoration: none; border-left: 3px solid transparent; }
#nav a:hover { background: rgba(255,255,255,.06); }
#nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: #5fd0b5; }
main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .layout { flex-direction: column; } .sidebar { width: auto; height: auto; position: static; } #nav { display: flex; flex-wrap: wrap; } #nav a { border-left: 0; padding: 8px 10px; } main { padding: 12px; } }
.stat { padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 22px; font-weight: 600; margin-top: 4px; }

button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #b8c4c1; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #0f4f45; border-color: #0f4f45; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-link { border: 0; background: none; color: var(--brand); padding: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd8ca; border-color: var(--brand); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 34px; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.fields .span2 { grid-column: span 2; }
.fields .full { grid-column: 1 / -1; }
.inline-check { display: flex; gap: 6px; align-items: center; color: var(--ink); font-size: 13px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters .field { margin: 0; min-width: 140px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7faf9; }
tfoot td { font-weight: 600; background: #fafbfb; }
.table-wrap { overflow-x: auto; }
.edit-table input, .edit-table select { padding: 5px 6px; }
.edit-table td { padding: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef1f0; color: #445; white-space: nowrap; }
.b-confirmed { background: #e6f0ff; color: #1f4f9a; }
.b-checked_in { background: #dff5ea; color: #1d6b43; }
.b-checked_out { background: #eceff1; color: #546e7a; }
.b-cancelled, .b-no_show { background: #fde8e6; color: #a1302a; }
.b-tentative { background: #fff4d6; color: #8a5a00; }
.b-pending { background: #fff4d6; color: #8a5a00; }
.b-paid, .b-delivered, .b-done { background: #dff5ea; color: #1d6b43; }
.b-booked { background: #e6f0ff; color: #1f4f9a; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; margin-right: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.empty { color: var(--muted); padding: 20px; text-align: center; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; }
.summary .total { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
.summary .total.due { color: var(--danger); }

/* Booking sheet */
.sheet-wrap { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.sheet { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.sheet th, .sheet td { border-right: 1px solid #edf0ef; border-bottom: 1px solid #edf0ef; padding: 0; height: 34px; min-width: 38px; width: 38px; text-align: center; font-size: 11px; }
.sheet thead th { position: sticky; top: 0; z-index: 3; background: #f7f9f8; padding: 4px 0; height: auto; }
.sheet thead th.today { background: #146356; color: #fff; }
.sheet th.villa { position: sticky; left: 0; z-index: 2; background: #fff; width: 130px; min-width: 130px; text-align: left; padding: 0 8px; font-size: 12px; }
.sheet thead th.villa { z-index: 4; background: #f7f9f8; }
.sheet td.we, .sheet th.we { background: #fafaf6; }
.sheet td.free { cursor: pointer; }
.sheet td.free:hover { background: var(--brand-soft); }
.sheet td.today-col { box-shadow: inset 2px 0 0 #5fd0b5; }
.sheet td.bk { padding: 2px 1px; }
.sheet .bar { height: 30px; border-radius: 5px; padding: 2px 6px; font-size: 11px; text-align: left; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; line-height: 13px; border: 1px solid rgba(0,0,0,.12); }
.sheet .bar b { font-weight: 600; }
.sheet .bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.sheet .bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.sheet .bar.st-checked_in { box-shadow: inset 0 -3px 0 rgba(0,0,0,.35); }
.sheet .bar.st-checked_out { opacity: .55; }
.sheet .bar.st-tentative { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.35) 0 6px, transparent 6px 12px); }
.sheet tr.unassigned th.villa { color: var(--danger); }
.sheet tfoot td, .sheet tfoot th { position: sticky; bottom: 0; background: #f7f9f8; font-weight: 600; height: 26px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; align-items: center; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16, 32, 28, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #10302a; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }

/* Invoice */
.invoice { background: #fff; max-width: 820px; margin: 0 auto; padding: 36px 40px; border: 1px solid var(--line); border-radius: var(--radius); }
.invoice .inv-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--brand); padding-bottom: 14px; margin-bottom: 18px; }
.invoice .inv-title { font-size: 26px; font-weight: 700; color: var(--brand); letter-spacing: .04em; }
.invoice table { margin-bottom: 14px; }
.invoice th { background: #f2f6f5; }
.invoice .sec { font-weight: 700; margin: 18px 0 6px; color: var(--brand); text-transform: uppercase; font-size: 12px; letter-spacing: .05em; }
.invoice .totals { margin-left: auto; width: 400px; max-width: 100%; }
.invoice .totals td { border: 0; padding: 4px 8px; }
.invoice .totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 15px; }
.invoice .totals tr.due td { font-weight: 700; font-size: 16px; color: var(--danger); }
.invoice .foot { margin-top: 30px; text-align: center; color: var(--muted); }

@media print {
  @page { size: A4; margin: 12mm; }
  body, :root { background: #fff; }
  .no-print, .sidebar, .page-head, #toasts { display: none !important; }
  main { padding: 0; }
  .invoice { border: 0; padding: 0; max-width: none; }
}
