*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: #f4f6f9;
  color: #1e293b;
  font-size: 15px;
  line-height: 1.45;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ── Login gate ── */
#login-gate {
  position: fixed; inset: 0; background: #1e293b;
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
#login-gate.hidden { display: none; }
.login-box {
  background: #fff; padding: 40px 34px; border-radius: 14px;
  width: 340px; box-shadow: 0 12px 44px rgba(0,0,0,.35);
}
.login-box h1 { font-size: 19px; margin-bottom: 6px; }
.login-box p { font-size: 13.5px; color: #64748b; margin-bottom: 20px; }
.login-box input {
  width: 100%; padding: 11px 13px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 15px; margin-bottom: 14px;
}
.login-box button {
  width: 100%; padding: 11px; background: #2563eb; color: #fff; border: none;
  border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14.5px;
}
.login-box button:hover { background: #1d4ed8; }
.login-error { color: #c2410c; font-size: 13px; margin-bottom: 10px; min-height: 16px; }

/* ── App shell ── */
#app.hidden { display: none; }

.toolbar {
  background: #1e293b; color: #f8fafc;
  padding: 16px 30px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.toolbar-title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 6px; }
.tab-btn {
  padding: 9px 20px; border-radius: 8px; font-size: 14px; font-weight: 600;
  color: #b6c2d4; cursor: pointer; background: transparent; border: 1px solid #3c4a63;
}
.tab-btn:hover { color: #f1f5f9; }
.tab-btn.active { background: #f4f6f9; color: #1e293b; border-color: #f4f6f9; }
.logout-btn {
  background: transparent; color: #b6c2d4; border: 1px solid #3c4a63;
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.logout-btn:hover { color: #f1f5f9; border-color: #64748b; }

.tab-panel { display: none; padding: 26px 30px; }
.tab-panel.active { display: block; }

.tab-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.tab-panel-header h2 { font-size: 17px; }

.btn-primary {
  padding: 10px 20px; background: #2563eb; color: #fff; border: none; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary {
  padding: 10px 20px; background: #eef2f7; color: #475569; border: none; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-secondary:hover { background: #e2e8f0; }

/* ── Card / list ── */
.card { background: #fff; border-radius: 10px; padding: 22px 26px; box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 22px; }
.card h2 { font-size: 16px; margin-bottom: 14px; }
.card-hint { font-size: 12.5px; color: #64748b; margin: -8px 0 14px; }

#working-days-table th, #working-days-table td { text-align: center; }
#working-days-table th:first-child, #working-days-table td:first-child { text-align: left; }
#working-days-table input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; }

table.list-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.list-table th, table.list-table td { padding: 11px 13px; border-bottom: 1px solid #e7ebf1; text-align: left; }
table.list-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
table.list-table tr:hover { background: #f8fafc; }
.type-chip { display: inline-flex; align-items: center; gap: 7px; }
.type-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 10px; text-transform: uppercase; letter-spacing: .03em; }
.status-applied { background: #fef3c7; color: #92400e; }
.status-approved { background: #dcfce7; color: #166534; }
.status-declined { background: #fee2e2; color: #991b1b; }
.row-actions button {
  border: none; background: transparent; cursor: pointer; font-size: 13px; color: #2563eb; font-weight: 600; margin-right: 10px;
}
.row-actions button.danger { color: #c2410c; }

/* ── Modal (Add / Edit Leave) ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(30,41,59,.55);
  display: flex; align-items: center; justify-content: center; z-index: 500;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 30px 32px;
  width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.modal-header h2 { font-size: 18px; }
.modal-close {
  border: none; background: transparent; font-size: 20px; line-height: 1; cursor: pointer;
  color: #94a3b8; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: #f1f5f9; color: #475569; }

#leave-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
#leave-form .field { display: flex; flex-direction: column; gap: 6px; }
#leave-form .field.full { grid-column: 1 / -1; }
#leave-form label { font-size: 11.5px; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .03em; }
#leave-form select, #leave-form input {
  padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14.5px;
}
#leave-form select:focus, #leave-form input:focus { outline: 2px solid #bfdbfe; border-color: #2563eb; }
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ── Legend ── */
.legend { display: flex; flex-wrap: wrap; gap: 12px 26px; padding: 14px 0; font-size: 12px; }
.legend-group { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.legend-group strong { color: #475569; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.lswatch { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.lswatch span { display: inline-block; width: 24px; height: 12px; border-radius: 3px; }
.lswatch span.applied-swatch {
  background: color-mix(in srgb, #334155 42%, white);
  border: 1.5px dashed #334155;
}
.lswatch span.holiday-swatch { background: #fde68a; }

/* ── Year tabs (calendar) ── */
.year-nav { display: flex; gap: 5px; margin-bottom: 12px; }
.year-tab {
  padding: 8px 18px; border-radius: 8px 8px 0 0; font-size: 13px; font-weight: 600;
  color: #475569; cursor: pointer; background: #e2e8f0; border: none;
}
.year-tab.active { background: #1e293b; color: #f8fafc; }
.year-section { display: none; }
.year-section.active { display: block; }

/* ── Month planner (calendar grid, borrowed from ph-cal) ── */
.p-row { display: flex; margin-bottom: 5px; }
.m-label {
  width: 72px; min-width: 72px; background: #1e293b; color: #f8fafc;
  display: flex; flex-direction: column; justify-content: center;
  padding: 7px 8px 5px; border-radius: 5px 0 0 5px; align-self: stretch;
}
.m-label .month-name { font-size: 16px; font-weight: 600; line-height: 1; }
.m-label .month-year { font-size: 10px; color: #94a3b8; margin-top: 3px; }
.m-col { flex: 1; display: flex; flex-direction: column; }

.day-subheader { display: flex; height: 16px; background: #f1f5f9; border: 1px solid #e2e8f0; border-left: none; border-radius: 0 5px 0 0; }
.dsh-cell { flex: 1; font-size: 7.5px; font-weight: 600; color: #64748b; display: flex; align-items: center; justify-content: center; border-right: 1px solid #e8edf4; }
.dsh-cell:last-child { border-right: none; }
.dsh-cell.weekend { background: #dde3ef; }
.dsh-cell.holiday { background: #fde68a; color: #92400e; }
.dsh-cell.empty { background: repeating-linear-gradient(-45deg, #dde3ec, #dde3ec 2px, #e8edf4 2px, #e8edf4 7px); }

.m-body { width: 100%; position: relative; border: 1px solid #e2e8f0; border-top: none; border-left: none; border-radius: 0 0 5px 0; background: #fff; overflow: hidden; }
.day-bg { position: absolute; inset: 0; display: flex; }
.day-bg .day-col { flex: 1; border-right: 1px solid #f1f5f9; height: 100%; position: relative; }
.day-bg .day-col:last-child { border-right: none; }
.day-bg .day-col.weekend { background: #dde3ef; }
.day-bg .day-col.holiday { background: #fdf3d0; }
.day-bg .day-col.empty { background: repeating-linear-gradient(-45deg, #dde3ec, #dde3ec 2px, #e8edf4 2px, #e8edf4 7px); }

.holiday-label {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center;
  white-space: normal; overflow-wrap: break-word; text-align: center;
  overflow: hidden;
  font-size: 8.5px; font-weight: 700; color: #92400e;
  line-height: 1.15; z-index: 3; pointer-events: none;
}

.events-layer { position: absolute; inset: 0; }
.ev-bar {
  position: absolute; border-radius: 3px; border: 1px solid rgba(0,0,0,0.18);
  overflow: hidden; padding: 3px 7px; cursor: default; display: flex; flex-direction: column;
  justify-content: center;
}
.ev-bar.approved { background: var(--c); }
.ev-bar.applied {
  background: color-mix(in srgb, var(--c) 40%, white);
  border: 1.5px dashed var(--c);
}
/* Font size is set dynamically per bar (see fitTextToWidth in app.js) so
   the name stays on one line instead of wrapping; ellipsis is the
   fallback once the shrink floor is hit. */
.ev-name { font-size: 11px; font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.ev-bar.applied .ev-name { color: #1e293b; }
.ev-bar.solo { padding: 5px 8px; }
.ev-bar.solo .ev-name { font-size: 12px; }

/* ── Summary tab ── */
.summary-controls { display: flex; gap: 18px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.summary-controls .field { display: flex; flex-direction: column; gap: 5px; }
.summary-controls label { font-size: 11.5px; font-weight: 600; color: #475569; text-transform: uppercase; }
.summary-controls select { padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14.5px; }
table.summary-table { width: 100%; border-collapse: collapse; font-size: 14.5px; background: #fff; }
table.summary-table th, table.summary-table td { padding: 11px 13px; border: 1px solid #e7ebf1; text-align: center; }
table.summary-table th:first-child, table.summary-table td:first-child { text-align: left; }
table.summary-table thead th { background: #1e293b; color: #f8fafc; font-size: 11px; text-transform: uppercase; }
table.summary-table tfoot td { font-weight: 700; background: #f1f5f9; }

.print-btn {
  background: #3b82f6; color: white; border: none; padding: 10px 20px; border-radius: 8px;
  cursor: pointer; font-size: 14px; font-weight: 600; margin-bottom: 14px;
}
.print-btn:hover { background: #2563eb; }

/* ── Print ── */
@media print {
  @page { size: A3 landscape; margin: 8mm; }
  .toolbar, .tabs, .print-btn, .modal-overlay, .tab-panel-header button { display: none !important; }
  #app > .tab-panel { display: none !important; }
  #app > .tab-panel.printing { display: block !important; }
  .year-section { display: none !important; }
  .year-section.active { display: block !important; }
}

@media (max-width: 900px) {
  .toolbar { flex-wrap: wrap; gap: 10px; }
  .tab-panel { overflow-x: auto; }
  #leave-form { grid-template-columns: 1fr; }
}
