/* Client area + Admin Area. Builds on site.css (same colors, fonts and form styles). */

.portal { background: var(--greige); padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(3rem, 7vw, 5rem); min-height: 60vh; }
.portal[aria-busy="true"] .frame > *:not(.portal-head):not(.back-link) { opacity: .55; transition: opacity .2s; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Page head ---------- */
.portal-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem 2rem; flex-wrap: wrap; margin-bottom: clamp(1.75rem, 4vw, 2.5rem); }
.portal-head .eyebrow { margin-bottom: .5rem; }
.portal-head h1 { font-size: clamp(2.4rem, 1.5rem + 4vw, 4.25rem); font-weight: 600; letter-spacing: .03em; line-height: 1.05; }
.portal-lede { color: var(--ink); max-width: 46ch; margin-top: 1rem; }
.notice { margin-top: 1rem; background: var(--white); border-left: 3px solid var(--accent); padding: .7rem 1rem; font-size: var(--text-sm); color: var(--ink); max-width: 52ch; }
.notice a { font-weight: 600; }
.portal-account { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; font-size: var(--text-sm); }
.portal-account__name { color: var(--muted); }
.link-plain { color: var(--ink); text-decoration: none; font-weight: 500; }
.link-plain:hover { text-decoration: underline; }
.back-link { margin-bottom: 1.25rem; font-size: var(--text-sm); }
.back-link a { color: var(--ink); text-decoration: none; }
.back-link a:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--ink); padding: .55rem 1rem; font-weight: 500; }
.btn--ghost:hover { background: var(--ink); color: var(--white); }
.btn--small { padding: .55rem 1.05rem; font-size: var(--text-xs); }
label.btn { cursor: pointer; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: var(--text-xs); color: var(--ink); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--black); }
.link-btn[disabled] { opacity: .5; cursor: progress; }
.link-btn--danger { color: var(--muted); }
.link-btn--danger:hover { color: var(--error); }
a.link-btn { display: inline; }

/* ---------- Avatars ---------- */
.avatar { width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center; background: var(--black); color: var(--white); font-family: var(--font-label); font-weight: 700; font-size: 1rem; overflow: hidden; }
.avatar--logo { background: var(--white); border: 1px solid var(--line); }
.avatar--logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.avatar--sm { width: 22px; height: 22px; font-size: .7rem; }
.avatar--sm.avatar--logo img { padding: 1px; }

/* ---------- Panels ---------- */
.panel { background: var(--white); box-shadow: var(--shadow); min-width: 0; }
.panel .form-card__head { padding: 1.4rem 1.75rem 1.2rem; }
.panel__head { background: var(--paper); padding: 1.4rem clamp(1.1rem, 3vw, 1.75rem) 0; }
.panel__head h2 { font-size: var(--text-lg); font-weight: 500; }
.panel__sub { font-size: var(--text-xs); color: var(--muted); margin-top: .3rem; }
.panel__head--split { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.panel__tools { display: flex; gap: .6rem; align-items: center; padding-bottom: 1rem; flex-wrap: wrap; }
.panel__body { padding: .5rem clamp(1.1rem, 3vw, 1.75rem) 1.5rem; }
.panel--narrow { max-width: 520px; }
.empty { text-align: center; color: var(--ink); padding: 2.5rem 1rem 1.5rem; }

.select-sm, .field select { font: inherit; font-size: var(--text-sm); color: var(--ink); background: var(--white); border: 1px solid #c9c2c3; border-radius: var(--radius); padding: .55rem .7rem; }
.field select { width: 100%; padding: .7rem .8rem; }
.field select:focus, .select-sm:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(32,28,37,.12); }
.field .label, .time-form .label { font-size: var(--text-xs); font-weight: 600; color: var(--ink); letter-spacing: .02em; }
.hint { font-size: var(--text-xs); color: var(--muted); margin: 0; }
.form-status.is-ok { background: #e8f4ee; color: var(--success); }
.form-actions--end { justify-content: flex-end; align-items: center; gap: 1rem; }

/* ---------- Filters / tabs ---------- */
.filters { display: flex; gap: 1.25rem; margin-top: 1rem; flex-wrap: wrap; }
.filters button, .subtabs button { background: none; border: 0; padding: .35rem 0 .6rem; font: inherit; font-size: var(--text-xs); color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.filters button span, .subtabs button span { color: var(--muted); }
.filters button[aria-selected="true"], .subtabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.filters button:hover, .subtabs button:hover { color: var(--ink); }

.sections { display: flex; gap: .5rem; margin: clamp(1.5rem, 3vw, 2rem) 0 1rem; flex-wrap: wrap; }
.sections button { font: inherit; font-size: var(--text-sm); font-weight: 500; letter-spacing: .02em; background: var(--paper); color: var(--ink); border: 0; padding: .7rem 1.1rem; cursor: pointer; }
.sections button span { color: var(--muted); }
.sections button[aria-selected="true"] { background: var(--black); color: var(--white); }
.sections button[aria-selected="true"] span { color: rgba(255,255,255,.7); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.stat { background: var(--white); padding: 1rem 1.1rem; }
.stat__num { font-family: var(--font-display); font-weight: 700; font-size: var(--text-xl); color: var(--ink); line-height: 1.1; margin: 0; }
.stat__label { font-family: var(--font-label); font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: .35rem 0 0; }
.stat__sub { font-size: var(--text-xs); color: var(--muted); margin: .15rem 0 0; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Pills & badges ---------- */
.pill { display: inline-flex; align-items: center; gap: .35rem; font-family: var(--font-label); font-size: .62rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding: .28rem .6rem; border-radius: 99px; vertical-align: middle; white-space: nowrap; line-height: 1; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--received { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.pill--in_progress { background: #fff4d6; color: #7a5200; }
.pill--done { background: var(--ink); color: var(--white); }
.badge { display: inline-block; font-family: var(--font-label); font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; background: var(--accent); color: var(--white); padding: .28rem .55rem; border-radius: 3px; vertical-align: middle; white-space: nowrap; line-height: 1; }
.badge--new { background: var(--ink); }

/* ---------- Tasks ---------- */
.task { padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task__top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.task__main { min-width: 0; }
.task__title { font-size: var(--text-base); font-weight: 600; color: var(--ink); line-height: 1.4; overflow-wrap: anywhere; }
.task__title .pill, .task__title .badge { margin-left: .35rem; }
.task.is-done .task__title { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--muted); }
.task__badges { display: flex; gap: .4rem; flex: none; }
.task__details { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--text-sm); color: var(--text); margin: .6rem 0 0; }
.task__client { display: flex; align-items: center; gap: .5rem; font-size: var(--text-sm); color: var(--muted); margin: .45rem 0 0; flex-wrap: wrap; }
.task__client strong { color: var(--ink); font-weight: 500; }
.task__client a { text-decoration: none; }
.task__client a:hover { text-decoration: underline; }
.task__billing { font-size: var(--text-xs); color: var(--muted); margin: .25rem 0 0; }
.task__meta { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; align-items: center; font-size: var(--text-xs); color: var(--muted); margin-top: .75rem; }
.task__meta strong { color: var(--ink); font-weight: 600; }
.task__actions { margin-left: auto; display: inline-flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.is-overdue { color: var(--error); font-weight: 600; }
.toggle { background: none; border: 0; padding: 0; font: inherit; font-size: var(--text-xs); color: var(--ink); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: .3rem; }
.toggle span { color: var(--muted); font-weight: 400; }
.toggle::after { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); margin-left: .25rem; transition: transform .15s; }
.toggle[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-1px); }
.toggle:hover { text-decoration: underline; }
.status-select { display: flex; align-items: center; gap: .5rem; font-size: var(--text-xs); color: var(--muted); flex: none; }
.status-select select { font: inherit; font-size: var(--text-sm); color: var(--ink); border: 1px solid #c9c2c3; border-radius: var(--radius); padding: .45rem .6rem; background: var(--white); }

.group { margin-top: 1.25rem; }
.group__title { display: flex; align-items: center; gap: .5rem; font-family: var(--font-label); font-size: var(--text-xs); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink); padding-bottom: .6rem; border-bottom: 1.5px solid var(--ink); }
.group__title span:not(.dot) { color: var(--muted); font-weight: 500; }
.group .dot { width: 8px; height: 8px; background: var(--muted); }
.group--high .dot { background: var(--accent); }
.group--normal .dot { background: var(--ink); }

.task__panel { margin-top: 1rem; background: var(--paper-2); border-left: 2px solid var(--ink); padding: 1rem clamp(.9rem, 2.5vw, 1.25rem) 1.1rem; }
.subtabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }

/* Threads and notes */
.thread, .notes { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .6rem; }
.msg { background: var(--white); border: 1px solid var(--line); padding: .7rem .9rem; max-width: min(560px, 92%); justify-self: start; }
.msg--mine { justify-self: end; background: #f1eeef; }
.msg__meta { font-size: var(--text-xs); color: var(--muted); margin: 0 0 .25rem; display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.msg__meta strong { font-family: var(--font-label); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); font-size: .66rem; }
.msg__body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--text-sm); color: var(--ink); margin: 0; }
.notes li { background: var(--white); border: 1px solid var(--line); padding: .7rem .9rem; }
.thread-empty { font-size: var(--text-sm); color: var(--muted); margin: 0 0 1rem; }
.reply { display: grid; gap: .4rem; }
.reply label { font-size: var(--text-xs); font-weight: 600; color: var(--ink); }
.reply textarea, .inline-form input, .inline-form textarea, .time-form input {
  width: 100%; font: inherit; font-size: var(--text-sm); color: var(--ink); background: var(--white);
  border: 1px solid #c9c2c3; border-radius: var(--radius); padding: .6rem .75rem; resize: vertical;
}
.reply textarea:focus, .inline-form input:focus, .inline-form textarea:focus, .time-form input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(32,28,37,.12); }
.reply__foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* Time */
.time-total { font-size: var(--text-sm); color: var(--ink); margin: 0 0 .75rem; }
.time-total strong { font-size: var(--text-lg); }
.time-list { list-style: none; margin: 0 0 1rem; padding: 0; border-top: 1px solid var(--line); }
.time-list li { display: grid; grid-template-columns: 4.5rem 1fr auto auto; gap: 1rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.time-list li span:nth-child(2) { color: var(--text); }
.time-list li span:nth-child(3) { color: var(--muted); font-size: var(--text-xs); }
.time-form { display: grid; gap: .6rem; }
.quick { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { font: inherit; font-size: var(--text-xs); background: var(--white); border: 1px solid #c9c2c3; border-radius: 99px; padding: .3rem .8rem; cursor: pointer; color: var(--ink); }
.chip:hover, .chip.is-on { border-color: var(--ink); background: var(--ink); color: var(--white); }
.time-grid { display: grid; grid-template-columns: 5.5rem 5.5rem 10.5rem minmax(0, 1fr); gap: .75rem; }
.time-grid label { font-size: var(--text-xs); color: var(--muted); }
@media (max-width: 640px) {
  .time-grid { grid-template-columns: 1fr 1fr; }
  .time-grid .field--grow, .time-grid .field:nth-child(3) { grid-column: 1 / -1; }
  .time-list li { grid-template-columns: 4rem 1fr auto; }
  .time-list li span:nth-child(3) { display: none; }
}

/* Inline forms (new task, edit task, clients) */
.inline-form { background: var(--paper-2); border: 1px solid var(--line); padding: 1.1rem clamp(1rem, 3vw, 1.5rem); margin: 1rem clamp(1.1rem, 3vw, 1.75rem) 0; display: grid; gap: .85rem; }
.task .inline-form, .client-row .inline-form { margin: .9rem 0 0; }
.client-row .inline-form { flex: 1; }
.inline-form h3 { font-size: var(--text-base); font-weight: 600; }
.inline-form .field label { font-size: var(--text-xs); }
.check { display: flex; gap: .5rem; align-items: center; font-size: var(--text-sm); color: var(--ink); cursor: pointer; }
.check input { width: 1rem; height: 1rem; accent-color: var(--ink); }

/* Contact messages */
.contact-msg { padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.contact-msg:last-child { border-bottom: 0; }
.contact-msg.is-handled .task__title { color: var(--muted); }
.contact-msg__when { font-size: var(--text-xs); color: var(--muted); margin: 0; text-align: right; flex: none; }

/* Clients */
.client-row { display: flex; gap: 1rem; align-items: flex-start; padding: 1.1rem 0; border-bottom: 1px solid var(--line); }
.client-row:last-child { border-bottom: 0; }
.client-row__main { flex: 1; min-width: 0; }
.client-row__main h4 { font-size: var(--text-base); font-weight: 600; color: var(--ink); }
.client-row__main p { font-size: var(--text-sm); margin: .15rem 0 0; overflow-wrap: anywhere; }
.client-row__main a { text-decoration: none; }
.client-row__main a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-weight: 400; }
.client-row__main p.muted { font-size: var(--text-xs); }
.client-row__actions { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: flex-end; padding-top: .2rem; }
@media (max-width: 640px) {
  .client-row { flex-wrap: wrap; }
  .client-row__actions { width: 100%; justify-content: flex-start; padding-left: calc(40px + 1rem); }
}

/* ---------- Client Area layout ---------- */
.client-grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: clamp(1rem, 2vw, 1.5rem); align-items: start; }
.client-grid .panel--form .contact-form { padding-top: 1.25rem; }
@media (max-width: 860px) { .client-grid { grid-template-columns: minmax(0, 1fr); } }
.task__panel .reply { margin-top: .25rem; }

/* ---------- Profile ---------- */
.logo-field { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .35rem; }
.logo-preview { width: 76px; height: 76px; display: grid; place-items: center; border: 1px dashed #b9b2b3; font-size: .7rem; color: var(--muted); background: var(--white); overflow: hidden; }
.logo-preview.has-logo { border-style: solid; border-color: var(--line); }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }

/* ---------- Login ---------- */
.portal--login .frame { display: grid; justify-items: center; }
.login-card { width: 100%; max-width: 440px; background: var(--white); box-shadow: var(--shadow); }
.login-card h1 { font-size: var(--text-xl); font-weight: 600; letter-spacing: .02em; margin-bottom: .5rem; }
.login-card .form-card__head { padding: 1.75rem 1.75rem 1.4rem; }
.login-sent { font-size: var(--text-sm); color: var(--ink); margin: 0; }
.login-sent strong { overflow-wrap: anywhere; }
.code-input { font-family: Menlo, Consolas, monospace !important; font-size: 1.6rem !important; letter-spacing: .45em; text-align: center; padding: .6rem .5rem !important; }
.login-help { margin-top: 1.5rem; font-size: var(--text-sm); color: var(--ink); text-align: center; }
.login-help a { font-weight: 600; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1.5rem); background: var(--ink); color: var(--white); padding: .8rem 1.2rem; font-size: var(--text-sm); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; max-width: calc(100vw - 2rem); text-align: center; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--error); }

@media (max-width: 640px) {
  .task__top { flex-direction: column; }
  .task--admin .status-select { align-self: flex-start; }
  .task__actions { margin-left: 0; }
  .contact-msg__when { text-align: left; }
}
.label .opt { margin-left: .3rem; font-weight: 400; color: var(--muted); }
.task--admin .task__client { flex-wrap: nowrap; align-items: flex-start; }
.task--admin .task__client .avatar { margin-top: .1rem; }

/* ---------- Task files ---------- */
.task__files { margin-top: .75rem; }
.files { list-style: none; margin: 0 0 .5rem; padding: 0; display: grid; gap: .35rem; }
.file { display: flex; align-items: center; gap: .75rem; background: var(--paper-2); border: 1px solid var(--line); padding: .5rem .75rem; font-size: var(--text-sm); min-width: 0; }
.file::before { content: ""; flex: none; width: 12px; height: 15px; border: 1.5px solid var(--ink); border-radius: 1px; clip-path: polygon(0 0, 65% 0, 100% 28%, 100% 100%, 0 100%); }
.file__name { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file__name:hover { text-decoration: underline; }
.file__size { color: var(--muted); font-size: var(--text-xs); flex: none; }
.file .link-btn { margin-left: auto; flex: none; }
.files__add { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .9rem; }
.files__add label.link-btn { font-weight: 600; cursor: pointer; }
.files__warn { font-size: var(--text-xs); color: #8a4b00; margin: 0; }
.field .files__warn { margin-top: .4rem; }
.file-input { font: inherit; font-size: var(--text-sm); color: var(--ink); width: 100%; padding: .55rem; border: 1px dashed #b9b2b3; border-radius: var(--radius); background: var(--white); }
.file-input::file-selector-button { font: inherit; font-size: var(--text-xs); font-weight: 600; background: var(--ink); color: var(--white); border: 0; padding: .45rem .8rem; margin-right: .75rem; cursor: pointer; }
