/* ==========================================================================
   Komoraro — Admin portal
   Builds on styles.css tokens and komoraro.css components (card, tiles,
   table, status, field, dd, dp, cal, toast).
   ========================================================================== */

body.page-admin, body.page-admin-login { background: var(--mist); }

/* ---------- login ---------- */
.alogin { min-height: 100vh; display: grid; place-items: center; padding: 40px 16px; }
.alogin__card { width: 100%; max-width: 440px; background: var(--white); border: 1px solid var(--line); border-radius: 28px; padding: 40px 36px; display: flex; flex-direction: column; gap: 22px; }
.alogin__card img { width: 170px; height: auto; }
.alogin__card h1 { font-size: 28px; line-height: 34px; font-weight: 600; }
.alogin__card p { color: var(--muted); font-size: 15px; }
.alogin__card form { display: flex; flex-direction: column; gap: 16px; }
.alogin__card .btn { width: 100%; }
.alogin__foot { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.alogin__hint { background: var(--mist); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); }

/* ---------- shell ---------- */
.adm { display: flex; min-height: 100vh; }
.adm__side { width: 264px; flex: none; background: var(--grey-900); color: var(--white); display: flex; flex-direction: column; gap: 10px; padding: 26px 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.adm__brand { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 8px 18px; }
.adm__brand img { width: 150px; height: auto; }
.adm__brand small { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--grey-300); font-weight: 600; }
.adm__nav { display: flex; flex-direction: column; gap: 2px; }
.adm__nav span.adm__group { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.5); padding: 14px 14px 6px; }
.adm__nav button { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; text-align: left; color: rgba(255,255,255,.85); font-size: 15px; transition: background .2s, color .2s; width: 100%; }
.adm__nav button svg { width: 18px; height: 18px; color: rgba(255,255,255,.7); flex: none; }
.adm__nav button:hover { background: rgba(255,255,255,.08); color: var(--white); }
.adm__nav button.is-active { background: var(--green); color: var(--on-green); font-weight: 500; }
.adm__nav button.is-active svg { color: var(--on-green); }
.adm__nav button .adm__badge { margin-left: auto; background: var(--green); color: var(--on-green); font-size: 11px; font-weight: 600; min-width: 20px; height: 20px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.adm__nav button.is-active .adm__badge { background: var(--grey-900); color: var(--white); }
.adm__nav button .adm__badge:empty { display: none; }
.adm__side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; }
.adm__side-foot a, .adm__side-foot button { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; color: rgba(255,255,255,.8); font-size: 14px; }
.adm__side-foot a:hover, .adm__side-foot button:hover { background: rgba(255,255,255,.08); color: var(--white); }
.adm__side-foot svg { width: 16px; height: 16px; }
.adm__close { display: none; }

.adm__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.adm__top { position: sticky; top: 0; z-index: 20; background: rgba(224,224,224,.9); backdrop-filter: blur(12px); display: flex; align-items: center; gap: 16px; padding: 18px 36px; border-bottom: 1px solid var(--line); }
.adm__top h1 { font-size: 24px; line-height: 30px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adm__burger { display: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--white); align-items: center; justify-content: center; flex: none; }
.adm__burger svg { width: 20px; height: 20px; }
.adm__search { position: relative; width: 300px; }
.adm__search input { width: 100%; height: 44px; border-radius: 30px; border: 1px solid var(--line); background: var(--white); padding: 0 16px 0 42px; font-size: 14px; outline: none; }
.adm__search input:focus { border-color: var(--green); }
.adm__search svg { position: absolute; left: 15px; top: 13px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.adm__user { display: inline-flex; align-items: center; gap: 10px; height: 44px; background: var(--white); border: 1px solid var(--line); border-radius: 30px; padding: 0 16px 0 4px; white-space: nowrap; line-height: 1.2; }
.adm__user i { width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: var(--on-green); display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-weight: 600; font-size: 13px; flex: none; }
.adm__user span { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-width: 0; }
.adm__user strong { font-size: 14px; font-weight: 600; line-height: 16px; color: var(--grey-900); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.adm__user small { font-size: 12px; line-height: 14px; color: var(--muted); }
.adm__main { padding: 30px 36px 60px; display: flex; flex-direction: column; gap: 24px; }
.adm__view { display: none; flex-direction: column; gap: 24px; }
.adm__view.is-active { display: flex; }
.adm__view .card { gap: 18px; }
.adm__view .tiles { grid-template-columns: repeat(5, 1fr); }
.adm__view .tile { background: var(--white); border: 1px solid var(--line); }
.adm__view .tile strong, .tiles .tile strong { color: var(--grey-900); }
.tile__delta { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tile__delta b { color: var(--green-dark); font-weight: 600; }
.tile__delta b.is-down { color: #b4532a; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; align-items: start; }
.grid-2 > .card { min-width: 0; }
.grid-2--wide { grid-template-columns: 2.3fr 1fr; }
.grid-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.grid-eq > .card { min-width: 0; }

/* ---------- toolbar: filters + search + actions ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar__spacer { flex: 1; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { height: 36px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--white); font-size: 14px; color: var(--ink); transition: all .2s; }
.filters button:hover { border-color: var(--green); }
.filters button.is-active { background: var(--green); border-color: var(--green); color: var(--on-green); }
.filters button span { opacity: .6; margin-left: 4px; }
.search { position: relative; width: 260px; max-width: 100%; }
.search input { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line); padding: 0 12px 0 38px; font-size: 14px; outline: none; background: var(--white); }
.search input:focus { border-color: var(--green); }
.search svg { position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.btn--xs { height: 36px; padding: 0 14px; font-size: 13px; }
.btn--danger { background: transparent; border-color: var(--line); color: #b4532a; }
.btn--danger:hover { background: #b4532a; border-color: #b4532a; color: var(--white); }
.btn svg { width: 14px; height: 14px; }

/* ---------- tables ---------- */
.adm__view .table th { white-space: nowrap; }
.table .cell-main { display: flex; flex-direction: column; gap: 2px; }
.table .cell-main small { color: var(--muted); font-size: 12px; }
.table .row-actions { display: flex; gap: 10px; white-space: nowrap; justify-content: flex-end; }
.table .row-actions button { color: var(--grey-900); font-size: 13px; font-weight: 500; text-decoration: underline; text-decoration-color: var(--green); text-underline-offset: 3px; }
.table .row-actions button.is-danger { color: #b4532a; }
.table .row-actions button:hover { text-decoration: underline; text-underline-offset: 3px; }
.table tr[data-row] { cursor: pointer; }
.table tr[data-row]:hover td { background: var(--mist); }
.table td:first-child, .table th:first-child { padding-left: 8px; }
.table .thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--mist); flex: none; }
.table .cell-prod { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.table .dd { width: 150px; }
.table .dd__btn { height: 36px; padding: 0 34px 0 12px; font-size: 13px; border-radius: 8px; }
.table .dd__btn svg { right: 10px; }
.table .dd__menu { min-width: 150px; }
.table .empty { color: var(--muted); text-align: center; padding: 30px 0; }
.status--amber { background: #fdebd3; color: #8a4b12; }
.status--red { background: #fbe3dc; color: #a03d18; }
.status--green { background: var(--green); color: var(--on-green); }
.status--mist { background: var(--mist); color: var(--muted); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--green-tint); color: var(--grey-900); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.cell-user { display: flex; align-items: center; gap: 12px; }

/* ---------- chart (single series, bars) ---------- */
.chart { display: flex; flex-direction: column; gap: 10px; }
.chart__meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chart__meta strong { font-size: 26px; font-weight: 600; }
.chart__meta span { font-size: 13px; color: var(--muted); }
.chart__plot { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; align-items: end; height: 170px; border-bottom: 1px solid var(--line); padding-bottom: 0; position: relative; }
.chart__bar { position: relative; display: flex; align-items: flex-end; height: 100%; }
.chart__bar i { display: block; width: 100%; background: var(--green); border-radius: 4px 4px 0 0; min-height: 3px; transition: height .6s var(--ease-out); }
.chart__bar:hover i { background: var(--green-500); }
.chart__bar.is-current i { background: var(--grey-300); }
.chart__bar .chart__tip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--black); color: var(--white); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s; }
.chart__bar:hover .chart__tip { opacity: 1; }
.chart__x { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; font-size: 12px; color: var(--muted); text-align: center; }
.chart__legend { font-size: 12px; color: var(--muted); display: flex; gap: 14px; }
.chart__legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; background: var(--green); }
.chart__legend i.is-lime { background: var(--grey-300); }
.breakdown { display: flex; flex-direction: column; gap: 10px; }
.breakdown div { display: grid; grid-template-columns: 130px 1fr 70px; align-items: center; gap: 12px; font-size: 14px; }
.breakdown div span:last-child { text-align: right; font-weight: 500; }
.breakdown i { display: block; height: 10px; border-radius: 5px; background: var(--mist); overflow: hidden; }
.breakdown i b { display: block; height: 100%; background: var(--green); border-radius: 5px; }

/* ---------- schedule list ---------- */
.agenda { display: flex; flex-direction: column; gap: 8px; }
.agenda div { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--mist); font-size: 14px; }
.agenda b { color: var(--green-dark); font-weight: 600; }
.agenda small { color: var(--muted); font-size: 12px; display: block; }

/* ---------- forms in admin ---------- */
.adm__view .field label, .modal .field label { font-size: 13px; color: var(--muted); }
.adm__view .form-grid, .modal .form-grid { gap: 16px 20px; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
.adm__view .field input, .adm__view .field textarea, .modal .field input, .modal .field textarea { padding: 11px 14px; font-size: 15px; border-radius: 8px; }
.adm__view .dd__btn, .modal .dd__btn, .adm__view .dp__btn, .modal .dp__btn { padding: 11px 40px 11px 14px; font-size: 15px; border-radius: 8px; min-height: 0; }
.adm__view textarea, .modal textarea { min-height: 90px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 42px; height: 24px; border-radius: 12px; background: var(--sage); position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--white); transition: left .2s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { left: 21px; }
.switch input:focus-visible + i { outline: 2px solid var(--grey-300); }
.rows { display: flex; flex-direction: column; }
.rows > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.rows > div:last-child { border-bottom: 0; }
.rows strong { font-weight: 500; font-size: 15px; display: block; }
.rows small { color: var(--muted); font-size: 13px; }
.avail { display: flex; flex-direction: column; }
.avail > div { display: grid; grid-template-columns: 110px 1fr 1fr auto; white-space: nowrap; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.avail > div:last-child { border-bottom: 0; }
.avail .dd { width: 100%; }
.avail > div.is-off .dd { opacity: .4; pointer-events: none; }
.upload { border: 1px dashed var(--grey); border-radius: 12px; padding: 18px; display: flex; align-items: center; gap: 14px; cursor: pointer; background: var(--mist); position: relative; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--sage); flex: none; }
.upload strong { font-size: 14px; font-weight: 500; display: block; }
.upload small { color: var(--muted); font-size: 12px; }
.plan-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.plan-card { border: 1px solid var(--line); border-radius: 18px; padding: 20px 22px; display: flex; flex-direction: column; gap: 8px; background: var(--white); }
.plan-card h4 { font-size: 18px; font-weight: 600; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.plan-card .price { font-size: 28px; font-weight: 600; }
.plan-card .price small { font-size: 13px; color: var(--muted); font-weight: 400; }
.plan-card p { color: var(--muted); font-size: 14px; }
.plan-card .form-actions { justify-content: flex-start; margin-top: 6px; }
.testimonial { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.testimonial:last-child { border-bottom: 0; }
.testimonial p { font-size: 15px; }
.testimonial small { color: var(--muted); font-size: 13px; }

/* ---------- modal + drawer ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s; }
.modal.is-open { opacity: 1; visibility: visible; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(25,25,25,.35); backdrop-filter: blur(4px); }
.modal__box { position: relative; width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow: auto; background: var(--white); border-radius: 24px; padding: 30px 32px; display: flex; flex-direction: column; gap: 22px; transform: translateY(16px); transition: transform .3s var(--ease-out); }
.modal.is-open .modal__box { transform: none; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal__head h3 { font-size: 22px; font-weight: 600; }
.modal__box form { display: flex; flex-direction: column; gap: 18px; }
.modal--drawer { justify-content: flex-end; padding: 0; }
.modal--drawer .modal__box { max-width: 520px; height: 100%; max-height: none; border-radius: 0; transform: translateX(30px); }
.modal--drawer.is-open .modal__box { transform: none; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile .avatar { width: 52px; height: 52px; font-size: 18px; }
.profile strong { font-size: 18px; font-weight: 600; display: block; }
.profile small { color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kv div { background: var(--mist); border-radius: 12px; padding: 12px 14px; }
.kv small { color: var(--muted); font-size: 12px; display: block; }
.kv strong { font-size: 16px; font-weight: 600; }
.modal h4 { font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 12px; }
.modal .table { font-size: 14px; }
.modal .table td { padding: 10px 10px 10px 0; }
.confirm p { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1340px) {
  .adm__view .tiles { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-2--wide { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .adm__side { position: fixed; left: 0; top: 0; z-index: 70; transform: translateX(-100%); transition: transform .3s var(--ease-out); box-shadow: 0 0 60px rgba(0,0,0,.2); width: 280px; }
  .adm.menu-open .adm__side { transform: none; }
  .adm__close { display: flex; width: 36px; height: 36px; border-radius: 50%; align-items: center; justify-content: center; color: var(--white); background: rgba(255,255,255,.1); }
  .adm__close svg { width: 18px; height: 18px; }
  .adm__burger { display: inline-flex; }
  .adm__top { padding: 14px 20px; }
  .adm__main { padding: 22px 20px 50px; }
  .adm__search { width: 200px; }
  .grid-eq { grid-template-columns: 1fr; }
  .form-grid--3 { grid-template-columns: 1fr 1fr; }
  .adm__view .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .adm__top h1 { font-size: 19px; }
  .adm__search { display: none; }
  .adm__user span { display: none; }
  .adm__user { padding: 0; width: 44px; justify-content: center; }
  .adm__main { padding: 16px 16px 40px; gap: 16px; }
  .adm__view { gap: 16px; }
  .adm__view .tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
  .adm__view .tile { padding: 16px; }
  .adm__view .tile strong { font-size: 24px; line-height: 30px; }
  .adm__view .card { padding: 18px 16px; }
  .search { width: 100%; }
  .toolbar .btn { width: 100%; justify-content: center; }
  .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .plan-cards, .kv { grid-template-columns: 1fr; }
  .avail > div { grid-template-columns: 1fr 1fr; }
  .avail > div > :first-child { grid-column: 1 / -1; }
  .modal { padding: 0; align-items: flex-end; }
  .modal__box { border-radius: 24px 24px 0 0; max-height: 92vh; padding: 22px 18px; }
  .modal--drawer .modal__box { max-width: none; border-radius: 0; }
  .chart__plot { height: 130px; gap: 6px; }
  .breakdown div { grid-template-columns: 100px 1fr 60px; }
  .agenda div { grid-template-columns: 48px 1fr; }
  .agenda div .status { grid-column: 2; justify-self: start; }
  .testimonial { grid-template-columns: 1fr; }
}
