/* ==========================================================================
   CredoBPO Operations Dashboard
   Brand colors live in :root — change them here and everything follows.
   ========================================================================== */
:root {
  --brand-primary: #0B3D5C;      /* deep teal-navy */
  --brand-primary-hover: #0F5278;
  --brand-dark: #2B2B2B;         /* charcoal */
  --surface: #F5F7F9;
  --white: #FFFFFF;
  --line: #DCE3E9;
  --line-soft: #EAEFF3;
  --text: #2B2B2B;
  --text-muted: #5A6772;
  --today-tint: #EEF5F9;
  --danger: #B3261E;
  --danger-tint: #FCEDEC;
  --success: #1B6E44;
  --success-tint: #E9F6EF;
  --focus: #1B7FBF;

  --font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 8px;
  --sidebar-w: 236px;
  --hour-h: 48px;                /* keep in sync with HOUR_H in calendar.js */
  --time-w: 58px;
  --col-min: 132px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45;
  color: var(--text); background: var(--surface);
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-primary); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand-primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--brand-primary-hover); }
.btn-outline { background: var(--white); border-color: var(--line); }
.btn-outline:hover { border-color: var(--brand-primary); }
.btn-ghost { background: transparent; color: var(--brand-primary); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-danger { background: var(--white); color: var(--danger); border-color: #E5B8B5; }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-sm { min-height: 32px; padding: 0 12px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: transparent; font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--line-soft); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label, .field .label { font-weight: 600; font-size: 13px; }
.optional { font-weight: 400; color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local],
input:not([type]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; background: var(--white);
  border: 1px solid #B9C4CD; border-radius: var(--radius);
}
textarea { resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface); color: var(--text); opacity: 1; border-color: var(--line); }
[aria-invalid=true] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; min-height: 0; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }

.form-error, .form-success {
  padding: 10px 12px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px;
}
.form-error { background: var(--danger-tint); color: #7F1B16; border: 1px solid #E5B8B5; }
.form-error ul { margin: 6px 0 0; padding-left: 18px; }
.form-success { background: var(--success-tint); color: #12502F; border: 1px solid #B7DEC8; }
.note { background: var(--today-tint); border: 1px solid #CFE0EA; border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; font-size: 13px; }

/* segmented control (view switch + Agent/Client choice) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); overflow: hidden; }
.seg-btn, .seg-opt span {
  display: block; padding: 8px 16px; border: 0; background: transparent; font-weight: 600; cursor: pointer;
}
.seg-btn + .seg-btn, .seg-opt + .seg-opt { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed=true], .seg-opt input:checked + span { background: var(--brand-primary); color: var(--white); }
.seg-opt { position: relative; display: block; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -3px; }

/* ---------- auth pages (login, hash.php) ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; background: var(--surface); }
.auth-card {
  width: 100%; max-width: 420px; background: var(--white); border: 1px solid var(--line);
  border-radius: 12px; padding: 32px 32px 28px; box-shadow: 0 8px 30px rgba(11, 61, 92, .08);
}
.auth-card-wide { max-width: 560px; }
.auth-logo { display: block; width: 150px; max-width: 60%; height: auto; margin: 0 auto 4px; }
.auth-tagline { text-align: center; color: var(--text-muted); font-size: 12px; letter-spacing: .04em; margin-bottom: 20px; }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 14px; color: var(--brand-primary); }
.auth-subtitle { font-size: 15px; font-weight: 700; margin: 22px 0 8px; }
.auth-note { margin-top: 16px; font-size: 13px; color: var(--text-muted); text-align: center; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.table th { font-weight: 600; color: var(--text-muted); }

/* ---------- app shell ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; }
.sidebar {
  background: var(--brand-primary); color: var(--white); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px;
  overflow-y: auto;
}
.brand { display: block; background: var(--white); border-radius: 10px; padding: 8px 10px; }
.brand img { display: block; width: 100%; height: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: var(--radius);
  color: #D5E3EC; text-decoration: none; font-weight: 500;
}
a.nav-link:hover { background: rgba(255, 255, 255, .1); color: var(--white); }
.nav-link.is-active { background: var(--white); color: var(--brand-primary); font-weight: 700; }
.nav-link.is-soon { color: #A9C2D1; cursor: default; }
.nav-link small { font-size: 11px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 99px; padding: 0 8px; }
.sidebar :focus-visible { outline-color: var(--white); }

.app-main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--white); border-bottom: 1px solid var(--line);
}
.page-title { font-size: 18px; font-weight: 700; color: var(--brand-primary); }
.menu-btn { display: none; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.userbox-text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; font-size: 13px; }
.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-primary); color: var(--white); font-weight: 700;
}
.role-badge { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.content { flex: 1; min-height: 0; padding: 16px 20px 20px; display: flex; flex-direction: column; }
.scrim { position: fixed; inset: 0; background: rgba(20, 30, 40, .45); z-index: 19; }

/* ---------- calendar panel ---------- */
.calendar-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.cal-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.cal-nav, .cal-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-title { font-size: 20px; font-weight: 700; margin-left: 8px; }
.cal-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 14px;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
}
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-primary); }
.inline-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.inline-field select { min-height: 34px; padding: 4px 8px; width: auto; max-width: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 0 auto; padding: 0; list-style: none; font-size: 12px; color: var(--text-muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 18px; height: 14px; border-radius: 3px; background: #DCEBF1; border-left: 4px solid var(--brand-primary); }
.swatch-client { background: #F6E9D2; border-left: 5px double #B7700A; }
.swatch-mine { background: #DCEBF1; border-left: 4px solid var(--brand-primary); box-shadow: 0 0 0 2px var(--brand-primary); }
.empty-note { color: var(--text-muted); font-size: 13px; }
.calendar { flex: 1; min-height: 0; transition: opacity .15s; }
.calendar.is-loading { opacity: .6; }

/* ---------- events (shared look) ---------- */
/* Tinted fill + solid left bar: readable text on any color; the bar style (solid vs double) separates
   agents from clients without relying on color alone. */
.ev {
  --ev: var(--brand-primary);
  background: color-mix(in srgb, var(--ev) 14%, #fff);
  border: 1px solid color-mix(in srgb, var(--ev) 28%, #fff);
  border-left: 4px solid var(--ev);
  border-radius: 6px; color: var(--text); cursor: pointer; font-size: 12px; line-height: 1.3;
}
.ev:hover { background: color-mix(in srgb, var(--ev) 22%, #fff); }
.ev-client { border-left-style: double; border-left-width: 5px; }
.ev.is-mine { box-shadow: 0 0 0 2px var(--brand-primary); }

/* ---------- time grid (day + week) ---------- */
.tg-scroll { height: 100%; overflow: auto; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.tg { min-width: calc(var(--time-w) + var(--cols) * var(--col-min)); }
.tg-head, .tg-body { display: grid; grid-template-columns: var(--time-w) repeat(var(--cols), minmax(var(--col-min), 1fr)); }
.tg-head { position: sticky; top: 0; z-index: 6; background: var(--white); border-bottom: 1px solid var(--line); }
.tg-corner, .tg-times { position: sticky; left: 0; z-index: 5; background: var(--white); }
.tg-dayhead {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border: 0; border-left: 1px solid var(--line);
  background: transparent; cursor: pointer; font-weight: 600;
}
.tg-dayhead:disabled { cursor: default; }
.tg-dayhead:not(:disabled):hover .dnum { background: var(--line-soft); }
.tg-dayhead .dow { font-size: 12px; color: var(--text-muted); }
.tg-dayhead .dnum { display: grid; place-items: center; min-width: 34px; height: 34px; border-radius: 50%; font-size: 17px; }
.tg-dayhead.is-today .dow { color: var(--brand-primary); }
.tg-dayhead.is-today .dnum { background: var(--brand-primary); color: var(--white); }
.tg-times { position: sticky; height: calc(var(--hour-h) * 24); }
.tg-hour { position: absolute; right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.tg-col {
  position: relative; height: calc(var(--hour-h) * 24); border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-h) - 1px), var(--line-soft) calc(var(--hour-h) - 1px), var(--line-soft) var(--hour-h));
}
.tg-col.is-today { background-color: var(--today-tint); }

.ev-block { position: absolute; padding: 3px 6px 3px 6px; overflow: hidden; min-height: 18px; display: flex; flex-direction: column; touch-action: pan-y; user-select: none; }
.ev-block .ev-time { font-weight: 600; font-size: 11px; }
.ev-block .ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ev-block .ev-owner { color: var(--text-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-block.cont-before { border-top-left-radius: 0; border-top-right-radius: 0; border-top-style: dashed; }
.ev-block.cont-after  { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-style: dashed; }
.ev-block.is-dragging { z-index: 8; opacity: .85; cursor: grabbing; box-shadow: 0 6px 16px rgba(11, 61, 92, .3); }
.ev-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize; }
.ev-resize::after { content: ''; position: absolute; left: 50%; bottom: 2px; width: 22px; height: 2px; margin-left: -11px; border-radius: 2px; background: var(--ev); opacity: 0; }
.ev-block:hover .ev-resize::after { opacity: .7; }
.now-line { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid #D13B2E; z-index: 4; pointer-events: none; }
.now-line::before { content: ''; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: #D13B2E; }

/* ---------- month view ---------- */
.month { height: 100%; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.month-head, .month-grid { display: grid; grid-template-columns: repeat(7, minmax(96px, 1fr)); min-width: 700px; }
.month-head { position: sticky; top: 0; z-index: 2; background: var(--white); border-bottom: 1px solid var(--line); }
.month-dow { padding: 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-align: center; }
.month-grid { flex: 1; grid-template-rows: repeat(var(--rows), minmax(112px, 1fr)); }
.mcell { display: flex; flex-direction: column; gap: 2px; padding: 4px; min-width: 0; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.mcell:nth-child(7n) { border-right: 0; }
.mcell.is-out { background: var(--surface); }
.mcell.is-out .mcell-num { color: var(--text-muted); }
.mcell.is-today { background: var(--today-tint); }
.mcell-num {
  align-self: flex-start; display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 4px; border: 0; border-radius: 13px;
  background: transparent; font-weight: 600; font-size: 13px; cursor: pointer;
}
.mcell-num:hover { background: var(--line-soft); }
.mcell.is-today .mcell-num { background: var(--brand-primary); color: var(--white); }
.ev-chip { display: flex; gap: 5px; align-items: baseline; padding: 1px 5px; min-width: 0; }
.chip-time { font-weight: 600; font-size: 11px; flex: none; }
.chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { align-self: flex-start; border: 0; background: transparent; color: var(--brand-primary); font-weight: 600; font-size: 12px; padding: 2px 4px; cursor: pointer; text-decoration: underline; }

/* ---------- dialog ---------- */
.dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: 12px; box-shadow: 0 20px 60px rgba(11, 30, 45, .35); color: var(--text); }
.dialog::backdrop { background: rgba(20, 30, 40, .5); }
.dialog[open] { display: flex; }
.dialog form { display: flex; flex-direction: column; width: 100%; max-height: calc(100vh - 24px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 17px; font-weight: 700; color: var(--brand-primary); }
.dialog-body { padding: 16px 18px 2px; overflow-y: auto; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface); }
.spacer { flex: 1; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 10px 16px; border-radius: var(--radius); background: var(--brand-dark); color: var(--white); font-weight: 500; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.toast-error { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-grid; }
  .legend { margin-left: 0; }
}
@media (max-width: 600px) {
  .content { padding: 12px; }
  .topbar { padding: 8px 12px; }
  .userbox-text { display: none; }
  .range-title { font-size: 16px; margin-left: 0; width: 100%; }
  .field-row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
