:root {
    --bg: #f7f9fc;
    --bg-strong: #eef3f8;
    --panel: #ffffff;
    --line: rgba(108, 128, 150, 0.22);
    --text: #243041;
    --muted: #6b7785;
    --primary: #6a86a8;
    --primary-deep: #4f6e92;
    --accent: #d8c7a8;
    --green: #7c9b73;
    --red: #c16c5b;
    --shadow: 0 18px 36px rgba(74, 97, 123, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
    font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(106, 134, 168, 0.16), transparent 22%),
        linear-gradient(180deg, #fbfcfe 0%, var(--bg) 100%);
    overflow: hidden;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(480px, calc(100% - 32px));
    margin: 0 auto;
}

.login-card {
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-card h1 {
    margin: 0 0 24px;
    font-size: 34px;
}

.login-primary {
    display: block;
    width: 100%;
    padding: 16px 20px;
    font-size: 18px;
    text-align: center;
    text-decoration: none;
}

.login-subauth {
    margin-top: 20px;
    text-align: left;
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.login-subauth summary {
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    list-style: none;
}

.login-subauth summary::-webkit-details-marker {
    display: none;
}

.stack {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.error-text {
    min-height: 20px;
    margin: 14px 0 0;
    color: var(--red);
    font-size: 13px;
}

.app-shell {
    width: min(1680px, calc(100% - 24px));
    margin: 0 auto;
    padding: 12px 0 16px;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 12px;
    overflow: hidden;
}

.topbar,
.topbar-nav,
.topbar-meta,
.entry-header,
.entry-tools,
.form-footer,
.action-row,
.list-header,
.analysis-header,
.status-inline,
.segmented,
.master-tabs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar {
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    gap: 12px;
}

.topbar-brand h1 {
    margin: 0;
    font-size: 22px;
    white-space: nowrap;
}

.eyebrow,
.panel-kicker,
.status-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--muted);
}

.eyebrow { margin: 0 0 6px; }

.topbar-nav,
.topbar-meta {
    min-width: 0;
}

.topbar-nav {
    flex: 1 1 auto;
    overflow: visible;
    padding: 2px;
    position: relative;
}

.nav-dropdown {
    position: relative;
    display: inline-flex;
}

.nav-dropdown-right .nav-dropdown-menu {
    left: auto;
    right: 0;
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    display: none;
    flex-direction: column;
    padding: 10px 8px 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
    z-index: 120;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: flex;
}

.nav-dropdown-item {
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
}

.nav-dropdown-item:hover {
    background: var(--bg-strong);
}

.topbar-meta {
    flex: 0 0 auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.status-inline {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
}

.status-inline[hidden] {
    display: none;
}

.user-inline {
    color: var(--muted);
    white-space: nowrap;
}

.screen-tab {
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
}

.screen-tab.is-active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
    color: #fff;
}

.workspace {
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.screen {
    display: none;
    height: 100%;
    min-width: 0;
}

.screen.is-active {
    display: block;
}

.screen[data-screen="master"] {
    display: none;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
}

.screen[data-screen="master"].is-active {
    display: flex;
}

.screen-split {
    display: none;
    grid-template-rows: minmax(max-content, 0.31fr) minmax(0, 0.69fr);
    gap: 10px;
    min-height: 0;
}

.screen-split.is-active {
    display: grid;
}

.split-top,
.split-bottom,
.analysis-panel {
    min-height: 0;
    min-width: 0;
}

.split-top {
    overflow: visible;
}

.entry-panel,
.list-panel,
.analysis-panel,
.master-panels,
.master-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.entry-panel,
.list-panel,
.analysis-panel,
.master-panel {
    padding: 14px;
}

.entry-header,
.list-header,
.analysis-header {
    justify-content: space-between;
    margin-bottom: 8px;
}

.heading-group {
    min-width: 0;
}

.title-line {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.entry-header h2,
.analysis-header h2 {
    margin: 0;
    font-size: 24px;
}

.list-header h3 {
    margin: 0;
    font-size: 19px;
}

.form-blocks {
    display: grid;
    gap: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.form-row-compact {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.master-form {
    margin-bottom: 16px;
}

label span {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    color: #314255;
    font-weight: 600;
}

input, select, button {
    font: inherit;
}

input, select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
}

.title-control,
.analysis-tools select {
    width: auto;
    min-width: 140px;
}

input[readonly] {
    background: var(--bg-strong);
}

.flag-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.form-footer {
    justify-content: space-between;
    flex-wrap: wrap;
    padding-top: 4px;
}

.button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 9px 15px;
    cursor: pointer;
}

.button-small {
    padding: 7px 11px;
}

.button-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
    color: #fff;
}

.button-secondary {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.toggle-buttons {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
}

.toggle-button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 7px 11px;
    border-radius: 10px;
    cursor: pointer;
}

.toggle-button.is-active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
    border-color: transparent;
    color: #fff;
}

.toggle-button:disabled,
select:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.table-wrap {
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: auto;
    background: #fff;
    max-width: 100%;
}

.fill-height {
    height: calc(100dvh - 360px);
}

.fill-analysis {
    height: calc(100dvh - 240px);
    padding-bottom: 14px;
}

.list-tools,
.analysis-tools,
.analysis-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.list-header {
    align-items: center;
}

.list-header .list-tools {
    margin-left: auto;
    flex-wrap: nowrap;
}

.list-header input[type="search"] {
    width: 220px;
    min-width: 220px;
}

.aggregate-view {
    display: none;
}

.aggregate-view.is-active {
    display: block;
}

.invoice-action-panel {
    width: min(560px, 100%);
    margin: calc(16dvh) auto 0;
    padding: 28px 32px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: #fff;
    box-shadow: var(--shadow);
    text-align: center;
}

.invoice-action-row {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin-bottom: 18px;
}

.invoice-action-row label {
    min-width: 150px;
    text-align: left;
}

.invoice-action-buttons {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.invoice-action-note {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.rc-sales-layout {
    display: grid;
    grid-template-columns: minmax(0, 0.62fr) 440px;
    gap: 40px;
    align-items: start;
    justify-content: center;
    padding: 0 20px 14px;
}

.rc-sales-daily-wrap {
    min-width: 0;
}

.rc-sales-summary-column {
    position: sticky;
    top: 0;
}

.rc-sales-total-card {
    margin-bottom: 22px;
    padding: 18px 20px;
    border: 1px solid rgba(108, 128, 150, 0.18);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(72, 93, 118, 0.08);
}

.rc-sales-total-title {
    margin-bottom: 12px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.rc-sales-total-metrics {
    display: grid;
    gap: 12px;
}

.rc-sales-total-metric {
    display: grid;
    gap: 4px;
}

.rc-sales-total-label {
    font-size: 13px;
    color: var(--muted);
}

.rc-sales-total-value {
    font-size: 24px;
    line-height: 1.15;
    color: var(--text);
}

.rc-sales-summary-wrap {
    overflow: visible;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.rc-table-wrap {
    display: flex;
    justify-content: center;
    padding: 0 18px 16px;
}

.rc-table {
    width: auto;
    min-width: 680px;
    max-width: 980px;
    margin: 0 auto;
    table-layout: fixed;
    border: 1px solid rgba(108, 128, 150, 0.18);
}

.rc-table thead th,
.rc-table tbody td {
    border-right: 1px solid rgba(108, 128, 150, 0.16);
}

.rc-table thead th:last-child,
.rc-table tbody td:last-child {
    border-right: 0;
}

.rc-table th,
.rc-table td {
    padding: 11px 12px;
}

.rc-table th:nth-child(1),
.rc-table td:nth-child(1) {
    width: 92px;
}

.rc-table th:nth-child(2),
.rc-table td:nth-child(2) {
    width: 72px;
}

.rc-table th:nth-child(n + 3),
.rc-table td:nth-child(n + 3) {
    width: 116px;
}

.rc-table .num-cell {
    text-align: right;
}

.rc-sales-table {
    min-width: 0;
    table-layout: fixed;
}

.rc-sales-table th,
.rc-sales-table td {
    padding: 10px 12px;
    white-space: nowrap;
    border-right: 1px solid rgba(108, 128, 150, 0.16);
}

.rc-sales-table .num-cell {
    text-align: right;
}

.rc-sales-table th:last-child,
.rc-sales-table td:last-child {
    border-right: 0;
}

.rc-sales-table-daily {
    min-width: 520px;
}

.stone-sales-daily-table {
    width: 100%;
    min-width: 0;
}

.zando-sales-daily-table {
    width: 100%;
    min-width: 0;
}

.rc-sales-table-summary {
    min-width: 410px;
}

.stone-sales-summary-table,
.zando-sales-summary-table {
    min-width: 420px;
}

.zando-sales-summary-table {
    min-width: 520px;
}

.rc-sales-table-daily thead th {
    text-align: center;
}

.stone-sales-daily-table thead th,
.zando-sales-daily-table thead th {
    text-align: center;
}

.aggregate-view[data-aggregate-screen="stonesales"] .rc-sales-layout {
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 34px;
}

.aggregate-view[data-aggregate-screen="zandosales"] .rc-sales-layout {
    grid-template-columns: minmax(0, 1fr) 520px;
    gap: 34px;
}

.aggregate-view[data-aggregate-screen="stonesales"] .rc-sales-daily-wrap,
.aggregate-view[data-aggregate-screen="zandosales"] .rc-sales-daily-wrap {
    overflow-x: hidden;
}

.stone-sales-daily-table th:nth-child(1),
.stone-sales-daily-table td:nth-child(1) {
    width: 108px;
}

.stone-sales-daily-table th:nth-child(2),
.stone-sales-daily-table td:nth-child(2) {
    width: 180px;
}

.stone-sales-daily-table th:nth-child(3),
.stone-sales-daily-table td:nth-child(3) {
    width: 44px;
    text-align: right;
}

.stone-sales-daily-table th:nth-child(4),
.stone-sales-daily-table td:nth-child(4) {
    width: 74px;
    text-align: right;
}

.stone-sales-daily-table th:nth-child(5),
.stone-sales-daily-table td:nth-child(5),
.stone-sales-daily-table th:nth-child(6),
.stone-sales-daily-table td:nth-child(6) {
    width: 84px;
    text-align: right;
}

.stone-sales-daily-table th:nth-child(7),
.stone-sales-daily-table td:nth-child(7) {
    width: 142px;
}

.stone-sales-daily-table th:nth-child(8),
.stone-sales-daily-table td:nth-child(8),
.stone-sales-daily-table th:nth-child(9),
.stone-sales-daily-table td:nth-child(9) {
    width: 48px;
    text-align: center;
}

.stone-sales-daily-table th:nth-child(10),
.stone-sales-daily-table td:nth-child(10) {
    width: 88px;
    text-align: right;
}

.zando-sales-daily-table th:nth-child(1),
.zando-sales-daily-table td:nth-child(1) {
    width: 112px;
}

.zando-sales-daily-table th:nth-child(2),
.zando-sales-daily-table td:nth-child(2) {
    width: 220px;
}

.zando-sales-daily-table th:nth-child(3),
.zando-sales-daily-table td:nth-child(3),
.zando-sales-daily-table th:nth-child(4),
.zando-sales-daily-table td:nth-child(4) {
    width: 48px;
    text-align: right;
}

.zando-sales-daily-table th:nth-child(5),
.zando-sales-daily-table td:nth-child(5),
.zando-sales-daily-table th:nth-child(6),
.zando-sales-daily-table td:nth-child(6) {
    width: 96px;
    text-align: right;
}

.zando-sales-daily-table th:nth-child(7),
.zando-sales-daily-table td:nth-child(7) {
    width: 56px;
    text-align: center;
}

.zando-sales-summary-table th {
    width: 210px;
}

.zando-sales-summary-table td {
    width: 150px;
}

.rc-sales-table-summary th {
    width: 180px;
    color: var(--text);
}

.rc-sales-table-summary td {
    width: 115px;
}

.summary-cash {
    background: #fff4bf;
}

.summary-delivery-10 {
    background: #b9ddff;
}

.summary-delivery-4 {
    background: #dff0ff;
}

.summary-b-grade {
    background: #ffe1c4;
}

.status-negative {
    color: var(--red);
}

.subtle-negative-note {
    color: var(--red);
    font-size: 12px;
    font-weight: 500;
}

.sales-table {
    min-width: 1480px;
    font-size: 12px;
}

.sales-table th,
.sales-table td {
    padding: 10px 8px;
}

.compact-table {
    font-size: 12px;
}

.compact-table th,
.compact-table td {
    padding: 8px 8px;
    line-height: 1.25;
}

th, td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(108, 128, 150, 0.14);
    white-space: nowrap;
    text-align: left;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-strong);
    color: #41576d;
}

.stone-table {
    width: auto;
    min-width: 0;
    table-layout: auto;
    font-size: 12px;
}

.stone-table thead th {
    border: 1px solid rgba(108, 128, 150, 0.18);
    white-space: nowrap;
}

.stone-table tbody td {
    border: 1px solid rgba(108, 128, 150, 0.14);
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}

.stone-table tfoot td {
    border: 1px solid rgba(97, 120, 145, 0.24);
    background: #e9f0f7;
    font-weight: 700;
    white-space: nowrap;
}

.stone-table th,
.stone-table td {
    padding: 10px 12px;
    line-height: 1.45;
}

.stone-table th:first-child,
.stone-table td:first-child {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    width: 34%;
}

.stone-table th:nth-child(2),
.stone-table td:nth-child(2),
.stone-table th:nth-child(3),
.stone-table td:nth-child(3),
.stone-table th:nth-child(4),
.stone-table td:nth-child(4) {
    width: 22%;
    text-align: right;
}

.stone-product-header {
    text-align: center;
    background: #e8eff6;
}

.stone-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    max-width: 100%;
}

#purchaseStoneFields[hidden],
#purchaseRc40Fields[hidden] {
    display: none;
}

.stone-panel {
    flex: 0 0 auto;
    min-width: max-content;
    max-width: none;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
}

.stone-panel .table-wrap {
    overflow-x: hidden;
}

.stone-panel-header {
    padding: 14px 14px 8px;
    border-bottom: 1px solid var(--line);
}

.stone-panel-header h3 {
    margin: 0 0 4px;
    font-size: 17px;
}

.stone-total-row td:first-child {
    text-align: center;
}

.master-panels {
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px;
    overflow: hidden;
}

.master-tabs {
    display: inline-flex;
    gap: 8px;
    margin-bottom: 10px;
}

.master-panel {
    display: none;
    height: 100%;
    min-height: 0;
    overflow: auto;
    padding-bottom: 18px;
}

.master-panel.is-active {
    display: block;
}

.master-list,
.user-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 10px;
}

.master-row,
.user-card {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
}

.toast-area {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: grid;
    gap: 10px;
    z-index: 50;
}

.toast {
    min-width: 220px;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(36, 48, 65, 0.96);
    color: #fff;
    box-shadow: var(--shadow);
}

.toast.success {
    background: rgba(124, 155, 115, 0.96);
}

@media (max-width: 1100px) {
    .form-row,
    .form-row-compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .fill-height,
    .fill-analysis,
    .master-panels {
        height: auto;
        min-height: 320px;
    }
}

@media (max-width: 760px) {
    .app-shell {
        height: auto;
        min-height: 100dvh;
    }

    .topbar,
    .topbar-nav,
    .topbar-meta,
    .entry-header,
    .entry-tools,
    .form-footer,
    .list-header,
    .analysis-header {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-meta {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .topbar-nav {
        overflow: auto;
    }

    .form-row,
    .form-row-compact {
        grid-template-columns: 1fr;
    }

    .title-control,
    .analysis-tools select {
        width: 100%;
    }

    .screen-split {
        grid-template-rows: auto auto;
    }

    .rc-sales-layout {
        grid-template-columns: 1fr;
    }

    .rc-sales-summary-column {
        position: static;
    }
}
