/*
 * Rim Beauty Studio portal responsive layer.
 * Kept separate from app.css so workflow-specific styling can continue to evolve
 * without this patch overwriting prior UI fixes.
 */

html {
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

main.shell {
    width: 100%;
    flex: 1 0 auto;
    min-width: 0;
}

footer {
    flex: 0 0 auto;
    min-height: 0;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

.card,
.stat,
.auth-card,
.filterbar,
.client-preview,
.record,
.pagehead,
.sectionhead,
.twocol > *,
.formgrid > *,
.filtergrid > *,
.stack > * {
    min-width: 0;
    max-width: 100%;
}

input,
select,
textarea,
button,
.button {
    max-width: 100%;
}

textarea {
    resize: vertical;
}

/* Long invoice/document identifiers should wrap instead of widening the page. */
td,
th,
.note,
.flash,
.muted,
.record,
code {
    overflow-wrap: anywhere;
    word-break: normal;
}

/* Tables stay semantically tabular and scroll inside their own region on small screens. */
.tablewrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
}

.tablewrap > table {
    max-width: none;
}

/* Keep controls from forcing table cells wider than necessary. */
.invoice-entry-table input,
.invoice-entry-table select,
.invoice-entry-table output,
.invoice-entry-table .service-picker,
.invoice-entry-table .discount-control,
.invoice-entry-table .tax-checks {
    max-width: 100%;
}

.actions,
.inlineform,
.filterbar,
.sectionhead,
.pagehead,
.record,
.metricrow {
    min-width: 0;
}

/* Medium screens / tablets. */
@media (max-width: 1000px) {
    .shell {
        padding-left: 18px;
        padding-right: 18px;
    }

    .topbar {
        gap: 14px;
        padding-left: 18px;
        padding-right: 18px;
    }

    .topbar nav {
        gap: 10px;
    }

    .filtergrid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filtergrid > button,
    .filtergrid > .actions {
        justify-self: start;
    }

    .capgrid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .invoice-entry-table {
        min-width: 1050px;
    }
}

/* Phone / small tablet. */
@media (max-width: 760px) {
    .topbar {
        position: static;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px 12px;
        padding: 10px 14px;
    }

    .brand {
        min-width: 0;
    }

    .brand > span:last-child {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar .account {
        margin-left: 0;
        justify-self: end;
        white-space: nowrap;
    }

    .topbar nav {
        grid-column: 1 / -1;
        order: initial;
        width: 100%;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 6px;
        padding: 3px 0 5px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .topbar nav a {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        padding: 7px 10px;
        border: 1px solid var(--line);
        border-radius: 999px;
        background: #fff;
        white-space: nowrap;
    }

    .shell {
        padding: 22px 12px 36px;
    }

    h1 {
        font-size: clamp(26px, 8vw, 34px);
    }

    .pagehead,
    .sectionhead {
        align-items: stretch;
        flex-direction: column;
    }

    .pagehead > .actions,
    .sectionhead > .actions,
    .pagehead > form,
    .sectionhead > form {
        width: 100%;
    }

    .pagehead > .button,
    .pagehead > form > button,
    .sectionhead > form > button {
        width: 100%;
    }

    .card {
        padding: 15px;
        margin-bottom: 14px;
        border-radius: 14px;
    }

    .stats,
    .twocol,
    .formgrid,
    .filtergrid,
    .capgrid,
    .client-preview {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .wide {
        grid-column: auto;
    }

    .filterbar,
    .inlineform {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .filterbar label,
    .inlineform label,
    .filterbar .actions,
    .inlineform .actions {
        width: 100%;
        min-width: 0;
    }

    .filterbar button,
    .inlineform > button,
    .inlineform > .button {
        width: 100%;
    }

    .record {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .record > .actions,
    .record > form,
    .record > .mini {
        width: 100%;
    }

    .mini {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .mini input,
    .mini button {
        width: 100%;
        max-width: none;
    }

    .actions:not(.compact) {
        width: 100%;
    }

    .actions:not(.compact) > button,
    .actions:not(.compact) > .button,
    .actions:not(.compact) > a.button {
        flex: 1 1 180px;
    }

    .actions.compact {
        align-items: stretch;
    }

    .actions.compact > form,
    .actions.compact > .button,
    .actions.compact > a {
        flex: 1 1 auto;
    }

    .actions.compact form button {
        width: 100%;
    }

    .metricrow {
        align-items: flex-start;
        gap: 8px;
        flex-wrap: wrap;
    }

    .tablewrap {
        margin-left: -2px;
        margin-right: -2px;
        padding-bottom: 4px;
    }

    table:not(.invoice-entry-table) {
        min-width: 640px;
    }

    th,
    td {
        padding: 10px 8px;
    }

    .invoice-entry-table {
        min-width: 1180px;
    }

    .service-picker,
    .session-details,
    .discount-control,
    .tax-checks {
        min-width: 0;
    }

    .discount-control {
        align-items: stretch;
        flex-direction: column;
    }

    .discount-value,
    .money-compact,
    .service-price {
        width: 100%;
        min-width: 82px;
    }

    .tax-checks {
        gap: 5px;
    }

    footer {
        padding: 7px 14px;
        gap: 4px;
        text-align: center;
        flex-direction: column;
    }
}

/* Narrow phones. */
@media (max-width: 480px) {
    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .mark {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .brand {
        font-size: 13px;
    }

    .brand small {
        font-size: 9px;
    }

    .account span {
        display: none;
    }

    .shell {
        padding-left: 10px;
        padding-right: 10px;
    }

    .card,
    .auth-card {
        padding: 13px;
    }

    .auth-shell {
        min-height: auto;
        padding-top: 28px;
        padding-bottom: 28px;
    }

    .actions:not(.compact) {
        flex-direction: column;
        align-items: stretch;
    }

    .actions:not(.compact) > button,
    .actions:not(.compact) > .button,
    .actions:not(.compact) > a.button {
        width: 100%;
        flex: 0 0 auto;
    }

    .badge {
        white-space: nowrap;
    }

    table:not(.invoice-entry-table) {
        min-width: 600px;
    }

    .invoice-entry-table {
        min-width: 1160px;
    }
}

/* Touch targets without enlarging desktop controls. */
@media (hover: none) and (pointer: coarse) {
    button,
    .button,
    .topbar nav a,
    input,
    select {
        min-height: 42px;
    }

    input[type="checkbox"],
    input[type="radio"] {
        min-height: 0;
    }
}

/* Dashboard KPI and current-year invoice chart. */
:root {
    --dashboard-chart-value: #a66d82;
    --dashboard-chart-value-soft: #f2e3e9;
    --dashboard-chart-count: #3e6f78;
    --dashboard-warm: #fbf3e7;
}

.dashboard-pagehead h1 {
    margin-bottom: .2rem;
}

.dashboard-stats {
    align-items: stretch;
}

.dashboard-stat {
    min-height: 164px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.dashboard-stat::after {
    content: "";
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 999px;
    right: -42px;
    top: -48px;
    pointer-events: none;
}

.dashboard-stat--clients::after {
    background: var(--accent2);
    opacity: .72;
}

.dashboard-stat--outstanding {
    background: linear-gradient(145deg, #fff 0%, var(--dashboard-warm) 100%);
}

.dashboard-stat--outstanding::after {
    background: #f3ddc1;
    opacity: .48;
}

.dashboard-stat__topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dashboard-stat__label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.dashboard-stat__number {
    display: block !important;
    margin: 6px 0 2px !important;
    font-size: clamp(36px, 5vw, 48px) !important;
    line-height: 1;
    letter-spacing: -.035em;
    color: var(--ink);
    text-align: left;
}

.dashboard-stat__hint {
    color: var(--muted);
    font-size: 12px;
}

.dashboard-stat__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #c88654;
    box-shadow: 0 0 0 5px rgba(200,134,84,.12);
    position: relative;
    z-index: 1;
}

.dashboard-balance-list {
    display: grid;
    gap: 4px;
    margin-top: 8px;
    max-width: 340px;
}

.dashboard-balance-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 18px;
    font-size: 12px;
    color: var(--muted);
}

.dashboard-balance-row strong {
    color: var(--ink);
    font-size: 15px;
    font-weight: 800;
    margin-left: auto;
}

.dashboard-chart-card {
    padding: clamp(18px, 3vw, 26px);
}

.dashboard-chart-head {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 6px;
}

.dashboard-chart-head h2 {
    font-size: clamp(20px, 2.4vw, 25px);
    margin: 3px 0 4px;
    letter-spacing: -.015em;
}

.dashboard-chart-subtitle {
    margin: 0;
    max-width: 680px;
    font-size: 13px;
}

.dashboard-currency-form {
    flex: 0 0 auto;
}

.dashboard-currency-form label {
    min-width: 126px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
}

.dashboard-currency-form select {
    min-width: 112px;
    font-size: 13px;
    font-weight: 750;
    color: var(--ink);
    background-color: #fff;
}

.dashboard-chart-legend {
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: flex-end;
    margin: 12px 4px 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.dashboard-chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.dashboard-legend-swatch {
    width: 18px;
    height: 8px;
    display: inline-block;
}

.dashboard-legend-swatch--value {
    background: var(--dashboard-chart-value-soft);
    border: 1px solid var(--dashboard-chart-value);
    border-radius: 3px;
}

.dashboard-legend-swatch--count {
    height: 0;
    border-top: 2px solid var(--dashboard-chart-count);
    position: relative;
}

.dashboard-legend-swatch--count::after {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--dashboard-chart-count);
    position: absolute;
    left: 6px;
    top: -4px;
}

.dashboard-chart-shell {
    position: relative;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    margin-top: 2px;
    scrollbar-width: thin;
}

.dashboard-chart-shell canvas {
    display: block;
    min-width: 560px;
    max-width: none;
}

.dashboard-chart-tooltip {
    position: absolute;
    z-index: 4;
    min-width: 164px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255,253,250,.97);
    box-shadow: 0 10px 28px rgba(67,45,55,.13);
    pointer-events: none;
    font-size: 12px;
    color: var(--muted);
}

.dashboard-chart-tooltip strong {
    display: block;
    color: var(--ink);
    font-size: 13px;
    margin-bottom: 5px;
}

.dashboard-chart-tooltip span {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-top: 2px;
}

.dashboard-chart-tooltip b {
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.dashboard-chart-empty {
    min-height: 220px;
    display: grid;
    place-items: center;
}

@media (max-width: 700px) {
    .dashboard-chart-head {
        flex-direction: column;
        gap: 14px;
    }

    .dashboard-currency-form,
    .dashboard-currency-form label,
    .dashboard-currency-form select {
        width: 100%;
    }

    .dashboard-chart-legend {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .dashboard-stat {
        min-height: 146px;
    }
}
