:root {
    color-scheme: light;
    --ink: #202426;
    --muted: #667071;
    --subtle: #edf0ee;
    --line: #dfe4e7;
    --paper: #ffffff;
    --canvas: #eef2f5;
    --accent: #0284c7;
    --accent-dark: #075985;
    --accent-soft: #e0f2fe;
    --link: #0369a1;
    --blue: #438bd2;
    --warn: #b86d00;
    --danger: #bd3d32;
    --shadow: 0 18px 50px rgba(32, 36, 38, 0.12);
    --radius: 8px;
    font-family: Inter, "Noto Sans JP", "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
    font-size: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--ink);
    letter-spacing: 0;
    overflow-x: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

[hidden] {
    display: none !important;
}

a {
    color: var(--accent-dark);
    text-decoration: none;
}

.login-screen {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
}

.login-card {
    display: grid;
    width: min(420px, 100%);
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--paper);
    box-shadow: var(--shadow);
    padding: 24px;
}

.login-card h1 {
    margin: 0;
    font-size: 1.4rem;
}

.login-message {
    min-height: 1.4em;
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.login-error {
    color: #b42318;
}

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 28px;
    border-right: 1px solid var(--line);
    background: #fbfbf8;
    padding: 26px 18px;
}

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

.drawer-close,
.mobile-menu-button,
.mobile-drawer-backdrop,
.mobile-panel-export {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    font-weight: 800;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.brand h1,
.topbar h2,
.dialog-head h3 {
    margin: 0;
    letter-spacing: 0;
}

.brand h1 {
    font-size: 1.1rem;
}

.main-nav {
    display: grid;
    gap: 8px;
}

.nav-item {
    display: grid;
    grid-template-columns: 28px 1fr;
    align-items: center;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    padding: 8px 10px;
    text-align: left;
}

.nav-item:hover {
    background: var(--subtle);
}

.nav-item.active {
    border-color: #b8d5cf;
    background: var(--accent-soft);
    color: #073c37;
    font-weight: 700;
}


.nav-parent:hover {
    background: transparent;
}

.nav-subitem:hover {
    background: var(--subtle);
    color: var(--ink);
}

.mini-action:hover {
    background: var(--subtle);
}

.nav-icon {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    font-size: 16px;
    line-height: 1;
}

.sidebar-note {
    margin-top: auto;
    display: grid;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    color: var(--muted);
    font-size: 0.85rem;
}

.sidebar-note strong {
    color: var(--ink);
}

.workspace {
    min-width: 0;
    padding: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 12px;
    min-width: 0;
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar h2 {
    font-size: 1.45rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
}

.search-box {
    display: grid;
    grid-template-columns: 22px minmax(120px, 240px);
    align-items: center;
    width: min(292px, 100%);
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    padding: 0 10px;
}

.search-box span {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
}

.search-box input {
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
}

.button,
.icon-button,
.segment {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--ink);
}

.button {
    min-height: 32px;
    padding: 0 12px;
    font-weight: 700;
    white-space: nowrap;
    font-size: 0.88rem;
}

.button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--paper);
}

.button.primary:hover {
    background: var(--accent-dark);
}

.button.secondary {
    background: #fdfdfb;
}

.button.ghost {
    background: transparent;
}

.button.danger {
    border-color: #e7c6c2;
    color: var(--danger);
}

.button.full {
    width: 100%;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
    line-height: 1;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.metric {
    display: grid;
    gap: 4px;
    min-height: 64px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    padding: 10px 12px;
}

.metric span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.metric strong {
    font-size: 1.25rem;
}

.panel {
    min-width: 0;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
    box-shadow: 0 1px 0 rgba(32, 36, 38, 0.03);
}

.view {
    display: none;
}

.view.active {
    display: block;
    padding: 10px;
}

@media screen and (max-width: 768px) {
  .view.active{
    padding: 0;
  }
}

.panel-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
}

.panel-copy,
.result-count {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.panel-toolbar-side {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-left: auto;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

#home-view .panel-toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    padding: 6px 10px;
}

#home-view .panel-copy {
    flex: 1 0 100%;
}

#home-view .toolbar-controls {
    flex: 0 1 auto;
    align-items: end;
    justify-content: flex-start;
    gap: 6px;
}

#home-view .compact-control {
    grid-template-columns: 1fr;
    gap: 3px;
}

#home-year {
    width: 76px;
}

#home-month {
    width: 136px;
}

.compact-control {
    grid-template-columns: auto minmax(116px, 150px);
    align-items: center;
    gap: 6px;
}

.compact-control input {
    min-height: 30px;
}

.muted {
    color: var(--muted);
}

.segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.segment {
    min-height: 30px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 0.84rem;
}

.segment.active {
    border-color: #9dc8c1;
    background: var(--accent-soft);
    color: #073c37;
    font-weight: 700;
}

.segment-divider {
    width: 1px;
    height: 22px;
    background: var(--line);
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.data-table {
    min-width: 920px;
}

.orders-table {
    min-width: 1070px;
    table-layout: fixed;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 6px 9px;
    text-align: left;
    vertical-align: middle;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #ffffff;
    color: #343a3d;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.25;
}

.data-table th:not(.check-column)::after {
    content: "";
}

td {
    font-size: 0.82rem;
    font-weight: 520;
    line-height: 1.35;
}

.orders-table tbody tr {
    cursor: pointer;
}

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

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

.orders-table th:nth-child(3),
.orders-table td:nth-child(3) {
    width: 240px;
}

body:not(.event-business-active) .orders-table .event-only-order-column {
    display: none !important;
}

body.event-business-active .orders-table .event-only-order-column {
    display: table-cell !important;
}

.event-business-active .orders-table {
    min-width: 1240px;
}

.orders-table th:nth-child(5),
.orders-table td:nth-child(5) {
    width: 150px;
}

.orders-table th:nth-child(6),
.orders-table td:nth-child(6) {
    width: 82px;
}

.orders-table th:nth-child(7),
.orders-table td:nth-child(7) {
    width: 82px;
}

.orders-table th:nth-child(8),
.orders-table td:nth-child(8) {
    width: 64px;
}

.orders-table th:nth-child(9),
.orders-table td:nth-child(9) {
    width: 110px;
}

.orders-table th:nth-child(10),
.orders-table td:nth-child(10) {
    width: 90px;
}

.orders-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sort-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    padding: 0;
    font: inherit;
    font-weight: 800;
}

.sort-button::after {
    content: "↕";
    color: #8fa0a8;
    font-size: 0.72rem;
    line-height: 1;
}

.sort-button.active::after {
    content: "▲";
    color: var(--link);
}

.sort-button.active[data-direction="desc"]::after {
    content: "▼";
}

tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr:nth-child(even) {
    background: #f6f6f6;
}

.data-table tbody tr:hover {
    background: #eef6fb;
}

.check-column {
    width: 34px;
    text-align: center;
}

.check-column input {
    width: 14px;
    min-height: 14px;
    padding: 0;
}

.client-link {
    color: var(--link);
    font-weight: 650;
    text-decoration: none;
}

.numeric {
    text-align: right;
    white-space: nowrap;
}

.nowrap {
    white-space: nowrap;
}

.cell-main {
    display: grid;
    gap: 2px;
}

.cell-main strong {
    font-size: 0.84rem;
}

.cell-main small {
    color: var(--muted);
    line-height: 1.45;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    min-height: 22px;
    border-radius: 999px;
    border: 1px solid var(--line);
    padding: 0 10px;
    font-size: 0.74rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-active,
.status-in_progress {
    border-color: #e2c178;
    background: #fff7df;
    color: #674200;
}

.status-delivered {
    border-color: #a8d5d0;
    background: #e7f5f1;
    color: #0c5048;
}

.status-unbilled {
    border-color: #9fc3df;
    background: #eef7ff;
    color: #235b83;
}

.status-invoiced {
    border-color: #d7dadd;
    background: #f0f2f1;
    color: #4c5556;
}

.status-unpaid {
    border-color: #9fc3df;
    background: #eef7ff;
    color: #235b83;
}

.status-paid {
    border-color: #a8d5d0;
    background: #e7f5f1;
    color: #0c5048;
}

.row-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
}

.row-actions .button {
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.78rem;
}

.url-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    min-height: 24px;
    border: 1px solid #bad5d0;
    border-radius: var(--radius);
    background: #f1faf7;
    padding: 0 8px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.78rem;
}

.text-link {
    border: 0;
    background: transparent;
    color: var(--link);
    font-weight: 800;
    padding: 0;
}

.grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 14px;
}

.master-card {
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}

.master-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.master-card h3 {
    margin: 0;
    font-size: 1rem;
}

.master-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.meta-list {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.86rem;
}

.scope-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 22px;
    border-radius: 999px;
    border: 1px solid var(--line);
    padding: 0 9px;
    font-size: 0.74rem;
    font-weight: 800;
}

.client-scope {
    border-color: #9fc3df;
    background: #eef7ff;
    color: #235b83;
}

.default-scope {
    border-color: #d7dadd;
    background: #f0f2f1;
    color: #4c5556;
}

.service-tabs {
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
}

.services-table {
    min-width: 940px;
    table-layout: fixed;
}

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

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

.services-table th:nth-child(5),
.services-table td:nth-child(5),
.services-table th:nth-child(6),
.services-table td:nth-child(6) {
    width: 96px;
}

.services-table th:nth-child(7),
.services-table td:nth-child(7) {
    width: 76px;
}

.services-table td:nth-child(3),
.services-table td:nth-child(4) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clients-table {
    min-width: 1240px;
    table-layout: fixed;
}

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

.clients-table th:nth-child(2),
.clients-table td:nth-child(2),
.clients-table th:nth-child(4),
.clients-table td:nth-child(4) {
    width: 132px;
}

.clients-table th:nth-child(3),
.clients-table td:nth-child(3) {
    width: 190px;
}

.clients-table th:nth-child(7),
.clients-table td:nth-child(7) {
    width: 170px;
}

.clients-table th:nth-child(8),
.clients-table td:nth-child(8) {
    width: 76px;
}

.clients-table td:nth-child(1),
.clients-table td:nth-child(3),
.clients-table td:nth-child(5),
.clients-table td:nth-child(6),
.clients-table td:nth-child(7) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
}

.settings-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
    padding: 14px;
}

.settings-card h3 {
    margin: 0 0 6px;
    font-size: 0.98rem;
}

.settings-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.55;
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 120px;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 0 12px;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
}

.file-button input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    opacity: 0;
    pointer-events: none;
}

.home-dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
    gap: 10px;
    padding: 10px;
}

.dashboard-card {
    display: grid;
    gap: 12px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
    padding: 12px;
}

.dashboard-card.wide {
    grid-column: 1 / -1;
}

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

.dashboard-card-head h3 {
    margin: 0;
    font-size: 0.95rem;
}

.dashboard-card-head span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

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

.summary-grid article,
.summary-list div {
    display: grid;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fbfcfc;
    padding: 10px;
}

.summary-grid span,
.summary-list span {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
}

.summary-grid strong,
.summary-list strong {
    font-size: 1.1rem;
}

.summary-list {
    display: grid;
    gap: 8px;
}

.bar-chart,
.status-breakdown {
    display: grid;
    gap: 7px;
}

.bar-row,
.breakdown-row {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 74px;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
}

.breakdown-row {
    grid-template-columns: 70px minmax(0, 1fr) 54px;
}

.bar-row>span,
.breakdown-row>span {
    color: var(--muted);
    font-weight: 800;
}

.bar-row strong,
.breakdown-row strong {
    text-align: right;
    white-space: nowrap;
}

.bar-track {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #edf1f2;
}

.bar-track i {
    display: block;
    width: var(--bar-width);
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #00796b, #438bd2);
}

.company-form {
    padding: 10px;
}

.company-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    gap: 10px;
}

.form-block {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
}

.form-block-body {
    display: grid;
    gap: 10px;
    padding: 12px;
}

.section-head.compact {
    min-height: 44px;
    padding: 8px 12px;
}

.form-save-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.save-status {
    min-height: 1em;
    color: var(--accent-dark);
    font-size: 0.82rem;
    font-weight: 800;
}

.seal-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 86px auto;
    align-items: end;
    gap: 10px;
}

.seal-editor-preview {
    display: grid;
    place-items: center;
    width: 86px;
    height: 64px;
    border: 1px dashed var(--line);
    border-radius: 4px;
    background: #fff;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
}

.seal-editor-preview img,
.company-seal {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.company-preview {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: grid;
    align-content: start;
    gap: 6px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fbfcfc;
    padding: 14px;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.5;
}

.company-preview strong {
    color: var(--ink);
    font-size: 0.95rem;
}

.company-preview-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.company-preview-head.has-seal {
    grid-template-columns: minmax(0, 1fr) 78px;
}

.company-preview-head>div,
.invoice-company>div {
    display: grid;
    gap: 3px;
}

.company-seal {
    width: 78px;
    height: 78px;
}

.company-preview hr {
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
    margin: 8px 0;
}

.invoice-workflow {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.invoice-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
    padding: 8px;
}

.invoice-tab {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--muted);
    padding: 0 12px;
    font-size: 0.84rem;
    font-weight: 800;
}

.invoice-tab.active {
    border-color: #9dc8c1;
    background: var(--accent-soft);
    color: #073c37;
}

.invoice-tab-panel {
    display: none;
}

.invoice-tab-panel.active {
    display: grid;
    gap: 10px;
}

.invoice-issue-panel,
.invoice-section,
.invoice-preview-shell {
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
}

.section-head h3 {
    margin: 0;
    font-size: 0.95rem;
}

.section-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.invoice-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    align-items: end;
    padding: 10px 12px 12px;
}

.invoice-mode-switch {
    margin: 10px 12px 0;
}

.invoice-mode-panel {
    display: none;
}

.invoice-mode-panel.active {
    display: block;
}

.invoice-control-wide {
    grid-column: span 2;
}

.invoice-controls textarea {
    min-height: 32px;
}

.bulk-invoice-summary {
    border-top: 1px solid var(--line);
    padding: 8px 12px 10px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
}

label,
.field-block {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
    min-width: 0;
}

.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.copy-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.order-copy-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding-top: 4px;
}

.button.compact {
    min-height: 26px;
    padding: 0 9px;
    font-size: 0.75rem;
}

.copy-status {
    min-width: 9em;
    color: var(--accent-dark);
    font-size: 0.72rem;
    font-weight: 800;
    text-align: right;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 5px 8px;
    font-size: 0.86rem;
    font-weight: 600;
}

input[type="date"],
input[type="month"] {
    cursor: pointer;
}

textarea {
    min-height: 96px;
    resize: vertical;
    line-height: 1.5;
}

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

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

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

.form-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.invoice-order-list {
    display: block;
}

.issued-invoices {
    display: block;
}

.invoice-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 820px;
    border-bottom: 1px solid var(--line);
    padding: 8px;
}

.invoice-list-toolbar .button {
    min-height: 30px;
    padding: 0 10px;
    font-size: 0.78rem;
}

.invoice-table {
    min-width: 820px;
}

#issued-invoices .invoice-table,
#unpaid-invoices .invoice-table,
#paid-invoices .invoice-table {
    min-width: 1120px;
    table-layout: fixed;
}

#issued-invoices .invoice-table th:nth-child(1),
#issued-invoices .invoice-table td:nth-child(1),
#unpaid-invoices .invoice-table th:nth-child(1),
#unpaid-invoices .invoice-table td:nth-child(1),
#paid-invoices .invoice-table th:nth-child(1),
#paid-invoices .invoice-table td:nth-child(1) {
    width: 34px;
}

#issued-invoices .invoice-table th:nth-child(2),
#issued-invoices .invoice-table td:nth-child(2),
#unpaid-invoices .invoice-table th:nth-child(2),
#unpaid-invoices .invoice-table td:nth-child(2),
#paid-invoices .invoice-table th:nth-child(2),
#paid-invoices .invoice-table td:nth-child(2) {
    width: 142px;
}

#issued-invoices .invoice-table th:nth-child(8),
#issued-invoices .invoice-table td:nth-child(8),
#unpaid-invoices .invoice-table th:nth-child(8),
#unpaid-invoices .invoice-table td:nth-child(8),
#paid-invoices .invoice-table th:nth-child(8),
#paid-invoices .invoice-table td:nth-child(8) {
    width: 96px;
}

#issued-invoices .invoice-table th:nth-child(9),
#issued-invoices .invoice-table td:nth-child(9),
#unpaid-invoices .invoice-table th:nth-child(9),
#unpaid-invoices .invoice-table td:nth-child(9),
#paid-invoices .invoice-table th:nth-child(9),
#paid-invoices .invoice-table td:nth-child(9) {
    width: 230px;
}

#invoice-order-list .invoice-table {
    min-width: 620px;
    table-layout: fixed;
}

.manual-invoice-table {
    min-width: 760px;
    table-layout: fixed;
}

.manual-invoice-table th:nth-child(1),
.manual-invoice-table td:nth-child(1) {
    width: 25%;
}

.manual-invoice-table th:nth-child(2),
.manual-invoice-table td:nth-child(2) {
    width: auto;
}

.manual-invoice-table th:nth-child(3),
.manual-invoice-table td:nth-child(3) {
    width: 90px;
}

.manual-invoice-table th:nth-child(4),
.manual-invoice-table td:nth-child(4),
.manual-invoice-table th:nth-child(5),
.manual-invoice-table td:nth-child(5) {
    width: 120px;
}

.manual-invoice-table th:nth-child(6),
.manual-invoice-table td:nth-child(6) {
    width: 70px;
}

.manual-invoice-table input {
    min-height: 30px;
}

.manual-invoice-table .button {
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.76rem;
}

#invoice-order-list .invoice-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#invoice-order-list .invoice-table th:nth-child(1),
#invoice-order-list .invoice-table td:nth-child(1) {
    width: 34px;
}

#invoice-order-list .invoice-table th:nth-child(2),
#invoice-order-list .invoice-table td:nth-child(2) {
    width: 112px;
}

#invoice-order-list .invoice-table th:nth-child(4),
#invoice-order-list .invoice-table td:nth-child(4) {
    width: auto;
}

#invoice-order-list .invoice-table th:nth-child(5),
#invoice-order-list .invoice-table td:nth-child(5) {
    width: 64px;
}

#invoice-order-list .invoice-table th:nth-child(6),
#invoice-order-list .invoice-table td:nth-child(6) {
    width: 110px;
}

.invoice-table input[type="checkbox"] {
    width: 14px;
    min-height: 14px;
    padding: 0;
}

.invoice-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.invoice-actions .button {
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.78rem;
}

.status-canceled {
    border-color: #efc5bf;
    background: #fff1ef;
    color: #8b2d25;
}

.invoice-preview-shell {
    min-width: 0;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 46px;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
}

.preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.invoice-preview {
    box-sizing: border-box;
    width: min(794px, calc(100% - 28px));
    min-height: 1123px;
    margin: 14px auto;
    border: 1px solid #ccd3d0;
    background: #fff;
    padding: 34px;
    color: var(--ink);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.invoice-title-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(240px, 330px);
    gap: 24px;
    align-items: start;
    border-bottom: 3px solid var(--ink);
    padding-bottom: 18px;
}

.invoice-title-row h3 {
    margin: 0;
    font-size: 1.75rem;
}

.invoice-meta {
    display: grid;
    gap: 4px;
    text-align: right;
    color: var(--muted);
    font-size: 0.86rem;
}

.invoice-address {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
    gap: 24px;
    margin: 24px 0 16px;
}

.invoice-address h4,
.invoice-total h4,
.invoice-bank h4 {
    margin: 0 0 8px;
}

.invoice-client-name {
    display: grid;
    gap: 4px;
    margin-bottom: 12px;
}

.invoice-client-name h4 {
    margin: 0;
}

.invoice-address p {
    margin: 0 0 8px;
}

.invoice-company {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.invoice-company.has-seal {
    grid-template-columns: minmax(0, 1fr) 76px;
}

.invoice-company strong {
    color: var(--ink);
    font-size: 0.92rem;
}

.invoice-seal {
    width: 76px;
    height: 76px;
}

.invoice-total-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
    gap: 24px;
    align-items: stretch;
    margin-bottom: 18px;
}

.invoice-info-lines {
    display: grid;
    gap: 6px;
    margin: -4px 0 18px;
    color: var(--ink);
    font-size: 0.85rem;
}

.invoice-info-lines p {
    display: grid;
    grid-template-columns: 3.5em minmax(0, 1fr);
    gap: 10px;
    margin: 0;
}

.invoice-info-lines strong {
    color: var(--muted);
}

.invoice-bank {
    border: 1px solid var(--line);
    padding: 12px 14px;
    color: var(--muted);
    font-size: 0.82rem;
}

.invoice-bank p {
    margin: 0;
    line-height: 1.55;
}

.invoice-bank p+p {
    margin-top: 4px;
}

.invoice-total {
    border: 1px solid var(--ink);
    padding: 16px;
}

.invoice-total strong {
    display: block;
    font-size: 1.55rem;
}

.invoice-preview table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    margin-top: 22px;
}

.invoice-preview th:nth-child(1),
.invoice-preview td:nth-child(1) {
    width: 56%;
}

.invoice-preview th:nth-child(2),
.invoice-preview td:nth-child(2) {
    width: 12%;
    text-align: right;
}

.invoice-preview th:nth-child(3),
.invoice-preview td:nth-child(3),
.invoice-preview th:nth-child(4),
.invoice-preview td:nth-child(4) {
    width: 16%;
    text-align: right;
}

.invoice-preview th,
.invoice-preview td {
    padding: 10px 8px;
}

.invoice-preview .amount {
    text-align: right;
}

.invoice-note {
    margin-top: 28px;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.7;
}

dialog {
    width: min(760px, calc(100vw - 28px));
    border: 0;
    border-radius: var(--radius);
    padding: 0;
    box-shadow: var(--shadow);
}

#entry-dialog.order-entry-dialog {
    width: min(480px, calc(100vw - 28px));
}

dialog::backdrop {
    background: rgba(32, 36, 38, 0.42);
}

.dialog-card {
    display: grid;
    gap: 18px;
    padding: 22px;
}

.dialog-head,
.dialog-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dialog-actions>div {
    display: flex;
    gap: 8px;
}

.invoice-dialog {
    width: min(980px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
}

.invoice-dialog-card {
    gap: 0;
    padding: 0;
}

.invoice-dialog .dialog-head {
    border-bottom: 1px solid var(--line);
    padding: 16px 18px;
}

.invoice-dialog-toolbar {
    border-bottom: 1px solid var(--line);
}

.invoice-dialog-body {
    max-height: calc(100vh - 170px);
    overflow: auto;
    background: #eef2f3;
    padding: 12px 0;
}

.invoice-dialog-body .invoice-preview {
    margin-top: 0;
    margin-bottom: 0;
}

.empty-state {
    display: grid;
    place-items: center;
    gap: 6px;
    min-height: 120px;
    color: var(--muted);
    text-align: center;
    font-size: 0.86rem;
}

.empty-state strong {
    color: var(--ink);
}

.print-only {
    display: none;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    body.drawer-open {
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: min(292px, 86vw);
        gap: 18px;
        border-right: 1px solid var(--line);
        border-bottom: 0;
        box-shadow: var(--shadow);
        padding: 18px;
        overflow-y: auto;
        transform: translateX(-105%);
        transition: transform 180ms ease;
    }

    body.drawer-open .sidebar {
        transform: translateX(0);
    }

    .mobile-drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 39;
        display: block;
        border: 0;
        background: rgba(32, 36, 38, 0.42);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    body.drawer-open .mobile-drawer-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .drawer-close,
    .mobile-menu-button {
        display: grid;
    }

    .main-nav {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .nav-item {
        grid-template-columns: 28px 1fr;
        justify-items: stretch;
        min-height: 48px;
        padding: 9px 11px;
        text-align: left;
        font-size: 15px;
        font-weight: 800;
    }

    .nav-icon {
        display: grid;
        font-size: 18px;
    }

    .sidebar-note {
        display: grid;
        font-size: 0.92rem;
    }

    .workspace {
        padding: 18px;
    }

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

    .topbar-actions {
        display: grid;
        grid-template-columns: 1fr auto auto;
        width: 100%;
    }

    .search-box {
        width: 100%;
        grid-template-columns: 22px minmax(0, 1fr);
    }

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

    .home-dashboard,
    .company-layout {
        grid-template-columns: 1fr;
    }

    .company-preview {
        grid-column: auto;
        grid-row: auto;
    }

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

    .invoice-controls {
        grid-template-columns: 1fr;
    }

    .invoice-control-wide {
        grid-column: auto;
    }
}

@media (min-width: 769px) {
    .app-shell {
        grid-template-columns: 248px minmax(0, 1fr);
    }

    body.drawer-open {
        overflow: auto;
    }

    .sidebar,
    body.drawer-open .sidebar {
        position: static;
        inset: auto;
        z-index: auto;
        width: auto;
        box-shadow: none;
        overflow: visible;
        transform: none;
        transition: none;
    }

    .drawer-close,
    .mobile-menu-button,
    .mobile-drawer-backdrop {
        display: none !important;
    }

    .topbar {
        align-items: center;
        flex-direction: row;
    }

    .topbar-actions {
        display: flex;
        width: auto;
    }

    .search-box {
        width: min(292px, 100%);
        grid-template-columns: 22px minmax(120px, 240px);
    }
}

@media (max-width: 640px) {
    :root {
        font-size: 13px;
    }

    input,
    select,
    textarea {
        min-height: 32px;
        padding: 4px 7px;
        font-size: 13px;
    }

    input[type="date"],
    input[type="month"] {
        min-inline-size: 0;
        max-width: 100%;
        text-align: left;
    }

    .invoice-controls input[type="date"] {
        -webkit-appearance: none;
        appearance: none;
        display: block;
        inline-size: 100%;
        min-inline-size: 0 !important;
        max-inline-size: 100%;
        height: 32px;
        padding: 4px 24px 4px 7px;
        overflow: hidden;
        background-color: #fff;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23202426' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4M16 2v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 7px center;
        background-size: 13px 13px;
        line-height: 1;
        white-space: nowrap;
    }

    .invoice-controls input[type="date"]::-webkit-date-and-time-value {
        min-width: 0;
        margin: 0;
        text-align: left;
    }

    .invoice-controls input[type="date"]::-webkit-calendar-picker-indicator {
        width: 18px;
        height: 18px;
        margin: 0 -19px 0 0;
        padding: 0;
        opacity: 0;
    }

    .workspace {
        padding: 10px;
    }

    #export-button {
        display: none;
    }

    .mobile-panel-export {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: auto;
        min-width: 58px;
        min-height: 28px;
        padding: 0 10px;
        font-size: 0.78rem;
    }

    .topbar {
        gap: 10px;
    }

    .topbar-title {
        width: 100%;
    }

    .topbar h2 {
        font-size: 1.35rem;
    }

    .topbar-actions {
        width: 100%;
    }

    .search-box {
        width: 100%;
        min-width: 0;
    }

    .topbar-actions,
    .form-grid,
    .form-grid.two,
    .form-grid.three,
    .invoice-address,
    .invoice-total-row {
        grid-template-columns: 1fr;
    }

    .toolbar-controls,
    .form-save-row,
    .seal-editor {
        align-items: stretch;
        flex-direction: column;
    }

    .seal-editor {
        grid-template-columns: 1fr;
    }

    .compact-control {
        grid-template-columns: 1fr;
    }

    #entry-dialog.order-entry-dialog .order-form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    #entry-dialog.order-entry-dialog .order-form-dates label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-money label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(4) {
        grid-column: 1 / -1;
    }

    #entry-dialog.order-entry-dialog textarea {
        min-height: 74px;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .settings-card {
        align-items: stretch;
        flex-direction: column;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .metric {
        min-height: 50px;
        padding: 7px 9px;
    }

    .metric span {
        font-size: 0.78rem;
    }

    .metric strong {
        font-size: 1rem;
    }

    .preview-toolbar,
    .section-head,
    .dialog-actions,
    .field-label-row,
    .order-copy-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .panel-toolbar {
        align-items: flex-start;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        min-height: 0;
        padding: 6px;
    }

    .panel-toolbar>.segmented {
        flex: 1 1 min(100%, 240px);
    }

    .panel-toolbar>.panel-copy {
        flex: 1 1 100%;
    }

    .panel-toolbar-side {
        align-self: flex-start;
        gap: 6px;
        margin-left: auto;
    }

    .section-head.compact {
        align-items: flex-start;
        flex-direction: row;
    }

    .section-head.compact>div {
        flex: 1 1 auto;
        min-width: 0;
    }

    .section-head .mobile-panel-export {
        align-self: flex-start;
        margin-left: auto;
    }

    .toolbar-controls {
        flex: 1 1 100%;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: end;
        justify-content: flex-start;
        gap: 6px;
    }

    .toolbar-controls .compact-control {
        flex: 0 1 auto;
        min-width: 0;
        width: auto;
    }

    .toolbar-controls .compact-control input {
        width: auto;
        max-width: 100%;
    }

    #home-year {
        width: 78px;
    }

    #home-month {
        width: 136px;
    }

    .toolbar-controls input[type="month"] {
        -webkit-appearance: none;
        appearance: none;
        padding-right: 24px;
        background-color: #fff;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23202426' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4M16 2v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 7px center;
        background-size: 13px 13px;
    }

    .toolbar-controls input[type="month"]::-webkit-date-and-time-value {
        min-width: 0;
        margin: 0;
        text-align: left;
    }

    .toolbar-controls input[type="month"]::-webkit-calendar-picker-indicator {
        width: 18px;
        height: 18px;
        margin: 0 -19px 0 0;
        padding: 0;
        opacity: 0;
    }

    .toolbar-controls .mobile-panel-export {
        align-self: end;
        margin-left: auto;
    }

    #home-view .toolbar-controls {
        flex: 0 1 auto;
        gap: 4px;
    }

    #home-view #home-year {
        width: 72px;
    }

    #home-view #home-month {
        width: 128px;
    }

    @media screen and (max-width: 768px) {
        #home-view #home-month,#home-view #home-year {
        height: 36px;
    }
    }




    #home-view .toolbar-controls .mobile-panel-export {
        margin-left: 0;
    }

    .invoice-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 7px;
        row-gap: 8px;
        padding: 8px;
    }

    .invoice-controls label:first-child,
    .invoice-control-wide,
    .invoice-controls .button {
        grid-column: 1 / -1;
    }

    label,
    .field-block {
        gap: 3px;
        font-size: 0.8rem;
    }

    .button {
        min-height: 30px;
        font-size: 0.88rem;
    }

    .segmented,
    .status-segments {
        gap: 4px;
    }

    .segment {
        min-height: 28px;
        border-radius: 7px;
        padding: 0 6px;
        font-size: 0.78rem;
    }

    .segment-divider {
        height: 18px;
        margin: 0 1px;
    }

    .result-count {
        font-size: 0.78rem;
        line-height: 28px;
    }

    .data-table th,
    .data-table td {
        padding: 4px 5px;
    }

    .data-table th {
        font-size: 0.74rem;
    }

    .data-table td {
        font-size: 0.78rem;
        line-height: 1.18;
    }

    .orders-table {
        min-width: 720px;
    }

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

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

    .orders-table th:nth-child(3),
    .orders-table td:nth-child(3) {
        width: 200px;
    }

    .orders-table th:nth-child(5),
    .orders-table td:nth-child(5) {
        width: 120px;
    }

    .orders-table th:nth-child(6),
    .orders-table td:nth-child(6),
    .orders-table th:nth-child(7),
    .orders-table td:nth-child(7) {
        width: 62px;
    }

    .orders-table th:nth-child(8),
    .orders-table td:nth-child(8) {
        width: 42px;
    }

    .orders-table th:nth-child(9),
    .orders-table td:nth-child(9) {
        width: 84px;
    }

    .orders-table .status-pill {
        min-width: 52px;
        min-height: 20px;
        padding: 0 5px;
        font-size: 0.7rem;
    }

    .orders-table .sort-button {
        gap: 2px;
    }

    .services-table {
        min-width: 820px;
    }

    .clients-table {
        min-width: 1040px;
    }

    #issued-invoices .invoice-table,
    #unpaid-invoices .invoice-table,
    #paid-invoices .invoice-table {
        min-width: 0;
        display: block;
    }

    .invoice-list-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        min-width: 0;
        padding: 6px;
    }

    #issued-invoices .invoice-table thead,
    #unpaid-invoices .invoice-table thead,
    #paid-invoices .invoice-table thead,
    #invoice-order-list .invoice-table thead {
        display: none;
    }

    #issued-invoices .invoice-table tbody,
    #unpaid-invoices .invoice-table tbody,
    #paid-invoices .invoice-table tbody,
    #invoice-order-list .invoice-table tbody {
        display: grid;
        gap: 6px;
        padding: 6px;
    }

    #issued-invoices .invoice-table tr,
    #unpaid-invoices .invoice-table tr,
    #paid-invoices .invoice-table tr,
    #invoice-order-list .invoice-table tr {
        display: grid;
        grid-template-columns: 22px minmax(0, 1fr);
        gap: 2px 8px;
        border: 1px solid var(--line);
        border-radius: 6px;
        background: #fff;
        padding: 8px;
    }

    #issued-invoices .invoice-table td,
    #unpaid-invoices .invoice-table td,
    #paid-invoices .invoice-table td,
    #invoice-order-list .invoice-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        border-bottom: 0;
        padding: 2px 0;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    #issued-invoices .invoice-table td:nth-child(n),
    #unpaid-invoices .invoice-table td:nth-child(n),
    #paid-invoices .invoice-table td:nth-child(n),
    #invoice-order-list .invoice-table td:nth-child(n) {
        width: auto;
    }

    #issued-invoices .invoice-table td::before,
    #unpaid-invoices .invoice-table td::before,
    #paid-invoices .invoice-table td::before,
    #invoice-order-list .invoice-table td::before {
        flex: 0 0 auto;
        color: var(--muted);
        font-size: 0.7rem;
        font-weight: 800;
    }

    #issued-invoices .invoice-table td:nth-child(1),
    #unpaid-invoices .invoice-table td:nth-child(1),
    #paid-invoices .invoice-table td:nth-child(1),
    #invoice-order-list .invoice-table td:nth-child(1) {
        grid-row: 1 / span 2;
        align-self: start;
        padding-top: 2px;
    }

    #issued-invoices .invoice-table td:nth-child(n + 2),
    #unpaid-invoices .invoice-table td:nth-child(n + 2),
    #paid-invoices .invoice-table td:nth-child(n + 2),
    #invoice-order-list .invoice-table td:nth-child(n + 2) {
        grid-column: 2;
        min-width: 0;
    }

    #issued-invoices .invoice-table td:nth-child(2)::before,
    #unpaid-invoices .invoice-table td:nth-child(2)::before,
    #paid-invoices .invoice-table td:nth-child(2)::before {
        content: "番号";
    }

    #issued-invoices .invoice-table td:nth-child(3)::before,
    #unpaid-invoices .invoice-table td:nth-child(3)::before,
    #paid-invoices .invoice-table td:nth-child(3)::before {
        content: "発行日";
    }

    #issued-invoices .invoice-table td:nth-child(4)::before,
    #unpaid-invoices .invoice-table td:nth-child(4)::before,
    #paid-invoices .invoice-table td:nth-child(4)::before {
        content: "取引先";
    }

    #issued-invoices .invoice-table td:nth-child(5)::before,
    #unpaid-invoices .invoice-table td:nth-child(5)::before,
    #paid-invoices .invoice-table td:nth-child(5)::before {
        content: "期間";
    }

    #issued-invoices .invoice-table td:nth-child(6)::before,
    #unpaid-invoices .invoice-table td:nth-child(6)::before,
    #paid-invoices .invoice-table td:nth-child(6)::before {
        content: "件数";
    }

    #issued-invoices .invoice-table td:nth-child(7)::before,
    #unpaid-invoices .invoice-table td:nth-child(7)::before,
    #paid-invoices .invoice-table td:nth-child(7)::before {
        content: "金額";
    }

    #issued-invoices .invoice-table td:nth-child(8)::before,
    #unpaid-invoices .invoice-table td:nth-child(8)::before,
    #paid-invoices .invoice-table td:nth-child(8)::before {
        content: "入金";
    }

    #issued-invoices .invoice-table td:nth-child(9),
    #unpaid-invoices .invoice-table td:nth-child(9),
    #paid-invoices .invoice-table td:nth-child(9) {
        display: block;
        grid-column: 1 / -1;
        padding-top: 6px;
    }

    #issued-invoices .invoice-actions,
    #unpaid-invoices .invoice-actions,
    #paid-invoices .invoice-actions {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 5px;
    }

    #issued-invoices .invoice-actions .button,
    #unpaid-invoices .invoice-actions .button,
    #paid-invoices .invoice-actions .button {
        min-height: 28px;
        padding: 0 5px;
        font-size: 0.72rem;
    }

    #invoice-order-list .invoice-table {
        min-width: 0;
        display: block;
    }

    #invoice-order-list .invoice-table td:nth-child(2)::before {
        content: "納品日";
    }

    #invoice-order-list .invoice-table td:nth-child(3)::before {
        content: "品名";
    }

    #invoice-order-list .invoice-table td:nth-child(4)::before {
        content: "詳細";
    }

    #invoice-order-list .invoice-table td:nth-child(5)::before {
        content: "数量";
    }

    #invoice-order-list .invoice-table td:nth-child(6)::before {
        content: "金額";
    }

    .manual-invoice-table {
        min-width: 0;
        display: block;
    }

    .manual-invoice-table thead {
        display: none;
    }

    .manual-invoice-table tbody {
        display: grid;
        gap: 6px;
        padding: 6px;
    }

    .manual-invoice-table tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        border: 1px solid var(--line);
        border-radius: 6px;
        background: #fff;
        padding: 8px;
    }

    .manual-invoice-table td,
    .manual-invoice-table td:nth-child(n) {
        display: grid;
        gap: 3px;
        width: auto;
        border-bottom: 0;
        padding: 0;
    }

    .manual-invoice-table td::before {
        color: var(--muted);
        font-size: 0.7rem;
        font-weight: 800;
    }

    .manual-invoice-table td:nth-child(1),
    .manual-invoice-table td:nth-child(2),
    .manual-invoice-table td:nth-child(6) {
        grid-column: 1 / -1;
    }

    .manual-invoice-table td:nth-child(1)::before {
        content: "品名";
    }

    .manual-invoice-table td:nth-child(2)::before {
        content: "詳細";
    }

    .manual-invoice-table td:nth-child(3)::before {
        content: "数量";
    }

    .manual-invoice-table td:nth-child(4)::before {
        content: "単価（税抜）";
    }

    .manual-invoice-table td:nth-child(5)::before {
        content: "金額（税込）";
    }

    .manual-invoice-table td:nth-child(6) .button {
        justify-self: end;
    }

    .copy-actions {
        justify-content: flex-start;
    }

    .preview-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .copy-status {
        min-width: 0;
        text-align: left;
    }

    .dialog-actions>div {
        display: grid;
        grid-template-columns: 1fr;
    }

    .button {
        width: 100%;
    }

    .button.mobile-panel-export {
        width: auto;
    }

    .grid-list {
        grid-template-columns: 1fr;
    }

    .invoice-tabs {
        display: flex;
        gap: 4px;
    }

    .invoice-tab {
        width: auto;
        min-height: 28px;
        padding: 0 8px;
        font-size: 0.76rem;
    }

    .invoice-tabs .mobile-panel-export {
        margin-left: auto;
    }

    .invoice-preview {
        width: 794px;
        min-width: 794px;
        max-width: none;
        min-height: 1123px;
        margin: 8px 0;
        padding: 34px;
    }

    .invoice-title-row {
        grid-template-columns: minmax(220px, 1fr) minmax(240px, 330px);
        gap: 24px;
    }

    .invoice-meta {
        text-align: right;
    }

    .invoice-address {
        grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
    }

    .invoice-total-row {
        grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
    }

    .invoice-company.has-seal {
        grid-template-columns: minmax(0, 1fr) 76px;
    }

    .invoice-seal {
        width: 76px;
        height: 76px;
    }

    .invoice-preview th,
    .invoice-preview td {
        padding: 10px 8px;
        font-size: 0.82rem;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 16mm;
    }

    html,
    body {
        background: #fff;
        width: auto;
        min-height: 0;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .sidebar,
    .topbar,
    .metrics,
    .invoice-tabs,
    .invoice-issue-panel,
    .invoice-section,
    .invoice-controls,
    .preview-toolbar,
    .panel:not(#invoices-view) {
        display: none !important;
    }

    .app-shell,
    .workspace,
    .invoice-workflow {
        display: block;
        padding: 0;
    }

    #invoices-view,
    .invoice-preview-shell,
    .invoice-preview {
        border: 0;
        box-shadow: none;
    }

    .invoice-preview {
        width: auto;
        min-width: 0;
        min-height: 0;
        margin: 0;
        padding: 0;
        page-break-after: auto;
        zoom: 1 !important;
    }

    .invoice-preview table {
        width: 100%;
    }

    .invoice-preview thead {
        display: table-header-group;
    }

    .invoice-preview tr,
    .invoice-title-row,
    .invoice-address,
    .invoice-info-lines,
    .invoice-total-row,
    .invoice-note {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    body.printing-invoice-modal .app-shell {
        display: none !important;
    }

    body.printing-invoice-modal #invoice-preview-dialog {
        display: block !important;
        position: static !important;
        width: auto !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
    }

    body.printing-invoice-modal #invoice-preview-dialog::backdrop,
    body.printing-invoice-modal #invoice-preview-dialog .dialog-head,
    body.printing-invoice-modal #invoice-preview-dialog .preview-toolbar {
        display: none !important;
    }

    body.printing-invoice-modal .invoice-dialog-card,
    body.printing-invoice-modal .invoice-dialog-body {
        display: block !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        background: #fff !important;
    }

    body.printing-invoice-modal #invoice-modal-preview {
        width: auto !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        zoom: 1 !important;
    }
}

/* Misoca integration */
.misoca-layout {
    display: grid;
    gap: 18px;
}

.misoca-card {
    border: 1px solid var(--line, #dfe5e7);
    border-radius: 18px;
    background: #fff;
    padding: 20px;
}

.misoca-card .section-head {
    margin-bottom: 16px;
}

.misoca-card .section-head p:not(.eyebrow) {
    margin: 6px 0 0;
    color: var(--muted, #667174);
    line-height: 1.7;
}

.misoca-connection-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fbfc 100%);
}

.misoca-status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #d8e0e2;
    background: #f5f7f8;
    color: #596468;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.misoca-status-pill.connected {
    background: #eef8f2;
    border-color: #bfe0cb;
    color: #217044;
}

.misoca-status-pill.error {
    background: #fff2f0;
    border-color: #efc1ba;
    color: #a53728;
}

.misoca-status-detail {
    min-height: 24px;
    color: var(--muted, #667174);
    font-size: 13px;
    line-height: 1.7;
    margin-bottom: 14px;
}

.misoca-actions,
.misoca-submit-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.misoca-actions a.button {
    text-decoration: none;
}

.misoca-form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.misoca-form-grid label {
    min-width: 0;
}

.misoca-form-grid .misoca-wide {
    grid-column: span 3;
}

.misoca-order-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 20px 0 10px;
}

.misoca-order-head span {
    color: var(--muted, #667174);
    font-size: 13px;
}

.misoca-submit-row {
    justify-content: space-between;
    margin-top: 16px;
}

.misoca-sync-state {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    background: #f2f5f6;
    color: #667174;
}

.misoca-sync-state.synced {
    background: #eef8f2;
    color: #217044;
}

.misoca-empty {
    padding: 22px;
    text-align: center;
    color: var(--muted, #667174);
}

@media (max-width: 820px) {
    .misoca-card {
        padding: 16px;
    }

    .misoca-form-grid {
        grid-template-columns: 1fr 1fr;
    }

    .misoca-form-grid .misoca-wide {
        grid-column: span 2;
    }
}

@media (max-width: 560px) {
    .misoca-form-grid {
        grid-template-columns: 1fr;
    }

    .misoca-form-grid .misoca-wide {
        grid-column: span 1;
    }

    .misoca-actions>*,
    .misoca-submit-row .button {
        width: 100%;
    }

    .misoca-submit-row {
        align-items: stretch;
    }
}


/* HOME: Misoca invoice list */
.home-misoca-invoices-card {
    gap: 10px;
}

.home-invoice-head {
    align-items: flex-start;
    flex-wrap: wrap;
}

.dashboard-card-title {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.home-invoice-actions,
.home-invoice-row-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
}

.home-invoice-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.home-invoice-summary span {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fbfcfc;
    padding: 6px 8px;
}

.home-invoice-summary strong {
    color: var(--ink);
}

.home-invoice-table-wrap {
    border: 1px solid var(--line);
    border-radius: 4px;
}

.home-misoca-invoice-table th,
.home-misoca-invoice-table td {
    vertical-align: middle;
}

.home-invoice-row-actions {
    min-width: 175px;
}

@media (max-width: 768px) {
    .home-invoice-head {
        display: grid;
        grid-template-columns: 1fr;
    }

    .home-invoice-actions {
        width: 100%;
    }

    .home-invoice-actions .button {
        flex: 1 1 0;
        justify-content: center;
    }

    .home-invoice-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .home-misoca-invoice-table {
        min-width: 820px;
    }
}

/* Misoca invoice dedicated page + manual line items */
.misoca-invoice-page {
    display: grid;
    gap: 16px;
}

.misoca-invoice-page-card {
    min-width: 0;
}

.misoca-invoice-page-head {
    align-items: flex-start;
    flex-wrap: wrap;
}

.misoca-invoice-page-table {
    margin-top: 4px;
}

.misoca-manual-head {
    align-items: flex-end;
}

.misoca-manual-head>div {
    display: grid;
    gap: 4px;
}

.misoca-manual-head>div>span {
    color: var(--muted, #667174);
    font-size: 13px;
}

.misoca-manual-table input {
    width: 100%;
    min-width: 120px;
}

.misoca-manual-table .misoca-manual-number {
    min-width: 96px;
    text-align: right;
}

.misoca-billing-total {
    margin-top: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fbfcfc;
    text-align: right;
    font-weight: 900;
}

@media (max-width: 768px) {
    .misoca-invoice-page-head {
        display: grid;
        grid-template-columns: 1fr;
    }

    .misoca-invoice-page-head .home-invoice-actions {
        width: 100%;
    }

    .misoca-invoice-page-head .home-invoice-actions>* {
        flex: 1 1 auto;
    }

    .misoca-manual-table {
        min-width: 900px;
    }
}



/* =========================================================
   2026-08-29 FINAL RESPONSIVE UI
   Single authoritative layout layer for desktop / tablet / mobile.
   ========================================================= */
:root {
    --ink: #182230;
    --muted: #667085;
    --subtle: #f2f4f7;
    --line: #e4e7ec;
    --paper: #ffffff;
    --canvas: #f6f8fb;
    --accent: #0284c7;
    --accent-dark: #075985;
    --accent-soft: #e0f2fe;
    --link: #344054;
    --blue: #2e90fa;
    --warn: #b54708;
    --danger: #b42318;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 30px rgba(16, 24, 40, .06);
    --shadow-lg: 0 20px 52px rgba(16, 24, 40, .18);
    --radius: 10px;
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--canvas);
}

body {
    width: 100%;
    max-width: 100%;
    min-width: 320px;
    overflow-x: hidden;
    background: var(--canvas);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

svg {
    display: block;
}

.app-shell {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: 268px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    gap: 24px;
    border-right: 0;
    background: #0b1220;
    padding: 24px 16px 18px;
    color: #e4e7ec;
    box-shadow: 8px 0 28px rgba(16, 24, 40, .05);
    overflow-y: auto;
}

.brand {
    gap: 12px;
    padding: 0 6px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 11px;
    background: linear-gradient(145deg, #0ea5e9, #0284c7);
    color: #fff;
    box-shadow: 0 8px 20px rgba(2, 132, 199, .28);
}

.brand-mark svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: none;
}

.brand .eyebrow {
    color: #98a2b3;
    letter-spacing: .1em;
}

.brand h1 {
    color: #fff;
    font-weight: 800;
}

.main-nav {
    gap: 5px;
}

.nav-item {
    grid-template-columns: 34px minmax(0, 1fr);
    min-height: 44px;
    border: 0;
    border-radius: 9px;
    color: #d0d5dd;
    padding: 8px 10px;
    font-weight: 600;
    transition: background .16s ease, color .16s ease;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.nav-item.active {
    border-color: transparent;
    background: rgba(255, 255, 255, .10);
    color: #fff;
    box-shadow: inset 3px 0 0 #38bdf8;
    font-weight: 800;
}

.nav-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    color: #98a2b3;
}

.nav-item.active .nav-icon {
    color: #bae6fd;
    background: rgba(14, 165, 233, .16);
}

.nav-icon svg,
.icon-button svg,
.search-box svg,
.payment-method-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-note {
    border-color: rgba(255, 255, 255, .10);
    background: rgba(255, 255, 255, .035);
    color: #98a2b3;
    padding: 12px;
}

.sidebar-note strong {
    color: #f2f4f7;
}

.sidebar-note .button.ghost {
    border-color: rgba(255, 255, 255, .12);
    color: #d0d5dd;
}

.workspace {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 22px 24px 34px;
    overflow-x: clip;
}

.workspace>*,
.topbar>*,
.topbar-title>*,
.topbar-actions>*,
.metrics>*,
.panel>*,
.panel-toolbar>*,
.section-head>*,
.misoca-card>*,
.company-layout>*,
.home-dashboard>* {
    min-width: 0;
}

.topbar {
    width: 100%;
    max-width: 100%;
    margin-bottom: 16px;
    gap: 16px;
}

.topbar-title {
    gap: 12px;
}

.topbar .eyebrow {
    margin-bottom: 3px;
    color: #98a2b3;
}

.topbar h2 {
    font-weight: 800;
    letter-spacing: -.02em;
}

.topbar-actions {
    gap: 8px;
}

.search-box {
    min-width: 220px;
    height: 40px;
    border-color: #d0d5dd;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
}

.search-box span {
    color: #98a2b3;
}

.button,
.icon-button,
.segment,
.invoice-tab,
.file-button {
    border-color: #d0d5dd;
    border-radius: 9px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .035);
    transition: border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

.button {
    min-height: 38px;
    padding: 0 13px;
}

.button:hover:not(:disabled) {
    border-color: #98a2b3;
    box-shadow: 0 2px 5px rgba(16, 24, 40, .08);
}

.button.primary {
    border-color: #0284c7;
    background: #0284c7;
    color: #fff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 10px rgba(2, 132, 199, .16);
}

.button.primary:hover:not(:disabled) {
    border-color: #0369a1;
    background: #0369a1;
}

.button.secondary {
    background: #fff;
}

.button.ghost {
    box-shadow: none;
}

.button.compact {
   min-height: 30px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1;
    text-decoration: none;
}

.icon-button {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
}

.icon-button svg {
    width: 20px;
    height: 20px;
}

.metrics {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    min-width: 0;
    min-height: 72px;
    gap: 0;
    border-color: #e4e7ec;
    border-radius: 13px;
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
}

.metric span {
    color: #667085;
}

.metric strong {
    min-width: 0;
    letter-spacing: -.02em;
    white-space: nowrap;
}

.panel,
.dashboard-card,
.form-block,
.invoice-issue-panel,
.invoice-section,
.invoice-preview-shell,
.invoice-tabs,
.misoca-card,
.settings-card,
.login-card {
    border-color: #e4e7ec;
    border-radius: 13px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
}

.panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.panel-toolbar,
.section-head {
    border-bottom-color: #eaecf0;
}

.panel-toolbar {
    min-height: 54px;
    padding: 10px 15px;
}

.panel-copy,
.result-count,
.section-head p {
    color: #667085;
}

.section-head {
    min-height: 58px;
    padding: 13px 16px;
}

.section-head h3 {
    font-weight: 800;
}

.home-dashboard {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
    gap: 12px;
    padding: 12px;
}

.dashboard-card {
    border-radius: 12px;
    padding: 16px;
}

.summary-grid {
    gap: 10px;
}

.summary-grid article,
.summary-list div {
    border-color: #eaecf0;
    border-radius: 10px;
    background: #f9fafb;
    padding: 12px;
}

.summary-grid strong,
.summary-list strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.bar-track {
    background: #eef2f6;
}

.bar-track i {
    background: linear-gradient(90deg, #0284c7, #2e90fa);
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-color: #d0d5dd transparent;
}

.data-table {
    width: 100%;
}

th,
td {
    border-bottom-color: #eaecf0;
    padding: 9px 11px;
}

th {
    background: #f9fafb;
    color: #475467;
    letter-spacing: .01em;
}

td {
    color: #344054;
}

.data-table tbody tr:nth-child(even) {
    background: #fff;
}

.data-table tbody tr:hover {
    background: #f0f9ff;
}

.client-link {
    color: #344054;
    font-weight: 750;
}

.status-pill {
    min-height: 24px;
    border-radius: 999px;
}

input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 40px;
    border-color: #d0d5dd;
    border-radius: 9px;
    padding: 7px 10px;
    color: #344054;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .02);
    transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #38bdf8;
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

label,
.field-block {
    color: #475467;
}

.segment {
    min-height: 34px;
    background: #fff;
}

.segment.active,
.invoice-tab.active {
    border-color: #bae6fd;
    background: #e0f2fe;
    color: #075985;
}

.settings-grid {
    gap: 12px;
    padding: 12px;
}

.settings-card {
    border-radius: 12px;
    padding: 16px;
}

.company-form {
    padding: 12px;
}

.company-layout {
    gap: 12px;
}

.form-block,
.company-preview {
    border-radius: 12px;
}

.misoca-layout {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 14px;
}

.misoca-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 20px;
    background: #fff;
}

.misoca-connection-card {
    background: linear-gradient(180deg, #fff 0%, #f8fcff 100%);
}

.misoca-status-detail {
    border: 1px solid #e4e7ec;
    border-radius: 9px;
    background: #f9fafb;
    color: #475467;
    padding: 10px 12px;
}

.misoca-actions,
.misoca-submit-row {
    gap: 8px;
}

.misoca-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.payment-methods {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.payment-method-card {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-width: 0;
    border: 1px solid #e4e7ec;
    border-radius: 11px;
    background: #fff;
    padding: 12px 13px;
}

.payment-method-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: #f0f9ff;
    color: #0284c7;
}

.payment-method-icon svg {
    width: 22px;
    height: 22px;
}

.payment-method-card>div {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.payment-method-card strong {
    color: #344054;
}

.payment-method-card>div span {
    color: #667085;
    line-height: 1.35;
}

.payment-enabled {
    border: 1px solid #abefc6;
    border-radius: 999px;
    background: #ecfdf3;
    color: #067647;
    padding: 4px 8px;
    font-weight: 800;
}

.invoice-payment-note {
    border: 1px solid #e4e7ec;
    border-radius: 9px;
    background: #f9fafb;
    color: #475467;
    padding: 10px 12px;
    font-weight: 650;
    line-height: 1.5;
}

.invoice-payment-note span {
    color: #667085;
    font-weight: 550;
}

.misoca-billing-total {
    margin-top: 12px;
    border: 1px solid #bae6fd;
    border-radius: 10px;
    background: #f0f9ff;
    color: #0c4a6e;
    padding: 14px 16px;
    text-align: right;
    font-weight: 900;
}

.misoca-invoice-page,
.misoca-invoice-page-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.home-invoice-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}

.home-invoice-summary span {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    border: 1px solid #e4e7ec;
    border-radius: 9px;
    background: #f9fafb;
    padding: 8px 10px;
}

.home-invoice-actions,
.home-invoice-row-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.home-invoice-table-wrap {
    margin: 0 16px 16px;
    border: 1px solid #e4e7ec;
    border-radius: 10px;
}

.misoca-manual-table input,
.misoca-manual-table .misoca-manual-number {
    width: 100%;
    min-width: 0;
}

.login-screen {
    background: #f6f8fb;
}

.login-card {
    gap: 18px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(16, 24, 40, .12);
    padding: 30px;
}

.login-card h1 {}

dialog {
    max-width: calc(100vw - 24px);
}

.dialog-card {
    max-width: 100%;
}

/* Tablet */
@media (max-width: 980px) {
    .app-shell {
        display: block;
        width: 100%;
    }

    body.drawer-open {
        overflow: hidden;
    }

    .sidebar,
    body.drawer-open .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: min(310px, 88vw);
        height: 100vh;
        border-right: 0;
        padding: 20px 16px;
        box-shadow: var(--shadow-lg);
        overflow-y: auto;
        transform: translateX(-105%);
        transition: transform 180ms ease;
    }

    body.drawer-open .sidebar {
        transform: translateX(0);
    }

    .mobile-drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 39;
        display: block;
        border: 0;
        background: rgba(16, 24, 40, .54);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    body.drawer-open .mobile-drawer-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .drawer-close,
    .mobile-menu-button {
        display: grid !important;
    }

    .workspace {
        width: 100%;
        padding: 18px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .topbar-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        width: 100%;
    }

    .search-box {
        width: 100%;
        min-width: 0;
        grid-template-columns: 22px minmax(0, 1fr);
    }

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

    .home-dashboard,
    .company-layout {
        grid-template-columns: 1fr;
    }

    .company-preview {
        grid-column: auto;
        grid-row: auto;
    }

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

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

    .misoca-form-grid .misoca-wide {
        grid-column: span 2;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* Phone */
@media (max-width: 640px) {
    :root {}

    html,
    body,
    .app-shell,
    .workspace,
    .topbar,
    .metrics,
    .view,
    .panel,
    .misoca-layout,
    .misoca-invoice-page,
    .company-form,
    .settings-grid {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .workspace {
        margin: 0;
        padding: 12px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left));
        overflow-x: hidden;
    }

    .topbar {
        width: 100%;
        margin: 0 0 12px;
        padding: 0;
        gap: 10px;
    }

    .topbar-title {
        width: 100%;
    }

    .topbar h2 {}

    .topbar-actions {
        display: grid;
        grid-template-columns: 1fr auto;
        width: 100%;
        gap: 8px;
    }

    .search-box {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
        height: 44px;
    }

    #export-button {
        display: none;
    }

    #primary-action {
        grid-column: 1 / -1;
        width: 100%;
        min-height: 44px;
    }

    .mobile-panel-export {
        display: inline-flex;
        width: auto;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin: 0 0 12px;
        padding: 0;
    }

    .metric {
        min-height: 72px;
        padding: 11px 12px;
    }

    .metric span {}

    .metric strong {
        white-space: nowrap;
        word-break: keep-all;
    }

    .panel {
        border-radius: 11px;
    }

    .panel-toolbar {
        align-items: flex-start;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        min-height: 0;
        padding: 10px 12px;
    }

    .panel-toolbar>.panel-copy,
    .panel-toolbar>.segmented {
        flex: 1 1 100%;
    }

    .panel-toolbar-side {
        margin-left: auto;
    }

    .toolbar-controls {
        flex: 1 1 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: end;
        gap: 6px;
    }

    .toolbar-controls .compact-control {
        width: auto;
    }

    #home-year {
        width: 84px;
    }

    #home-month {
        width: 150px;
    }

    .home-dashboard {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
    }

    .dashboard-card {
        border-radius: 10px;
        padding: 12px;
    }

    .dashboard-card.wide {
        grid-column: auto;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .summary-grid article,
    .summary-list div {
        padding: 10px;
    }

    .bar-row {
        grid-template-columns: 32px minmax(0, 1fr) 66px;
        gap: 6px;
    }

    .breakdown-row {
        grid-template-columns: 62px minmax(0, 1fr) 48px;
        gap: 6px;
    }

    .button {
        width: auto;
        min-height: 40px;
        padding: 0 12px;
    }

    .button.full {
        width: 100%;
    }

    .button.compact {
        min-height: 34px;
    }

    input,
    select,
    textarea {
        min-width: 0;
        min-height: 44px;
    }

    input[type="date"],
    input[type="month"] {
        inline-size: 100%;
        min-inline-size: 0 !important;
        max-inline-size: 100%;
    }

    .segmented,
    .status-segments {
        width: 100%;
        gap: 5px;
    }

    .segment {
        flex: 0 1 auto;
        min-height: 34px;
        padding: 0 9px;
    }

    .service-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .service-tabs .segment {
        flex: 0 0 auto;
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        min-height: 0;
        padding: 12px;
    }

    .section-head.compact {
        flex-direction: row;
    }

    .settings-grid,
    .company-form {
        padding: 8px;
    }

    .settings-card {
        align-items: stretch;
        flex-direction: column;
        border-radius: 10px;
        padding: 14px;
    }

    .settings-card .button,
    .settings-card .file-button {
        width: 100%;
    }

    .company-layout {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .form-block-body {
        padding: 10px;
    }

    .form-grid,
    .form-grid.two,
    .form-grid.three {
        grid-template-columns: 1fr;
    }

    .seal-editor {
        grid-template-columns: 1fr;
    }

    .misoca-card {
        border-radius: 10px;
        padding: 12px;
    }

    .misoca-form-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .misoca-form-grid .misoca-wide {
        grid-column: auto;
    }

    .misoca-actions,
    .misoca-submit-row {
        align-items: stretch;
        flex-direction: column;
    }

    .misoca-actions>*,
    .misoca-submit-row .button {
        width: 100%;
    }

    .misoca-order-head,
    .misoca-manual-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .misoca-manual-head .button {
        width: 100%;
    }

    .payment-methods {
        grid-template-columns: 1fr;
    }

    .payment-method-card {
        grid-template-columns: 38px minmax(0, 1fr) auto;
        padding: 10px;
    }

    .payment-method-icon {
        width: 38px;
        height: 38px;
    }

    .misoca-billing-total {
        text-align: left;
    }

    .home-invoice-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .home-invoice-actions>* {
        width: 100%;
        justify-content: center;
    }

    .home-invoice-actions> :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .home-invoice-summary {
        display: grid;
        grid-template-columns: 1fr;
        padding: 0 12px 10px;
    }

    .home-invoice-summary span {
        width: 100%;
        justify-content: space-between;
    }

    .home-invoice-table-wrap {
        margin: 0;
        border: 0;
        border-radius: 0;
        overflow: visible;
    }

    /* Mobile table cards. Desktop remains spreadsheet-like. */
    .table-wrap:has(> .mobile-card-table),
    #clients-list.table-wrap,
    #services-list.table-wrap,
    #misoca-order-list.table-wrap,
    #misoca-client-list.table-wrap,
    #misoca-manual-items.table-wrap,
    #home-misoca-invoice-list.table-wrap {
        overflow: visible;
    }

    .mobile-card-table,
    .orders-table.mobile-card-table,
    .clients-table.mobile-card-table,
    .services-table.mobile-card-table,
    .home-misoca-invoice-table.mobile-card-table,
    .misoca-order-table.mobile-card-table,
    .misoca-client-table.mobile-card-table,
    .misoca-manual-table.mobile-card-table {
        display: block;
        width: 100%;
        min-width: 0;
        table-layout: auto;
    }

    .mobile-card-table thead,
    .orders-table.mobile-card-table thead {
        display: none;
    }

    .mobile-card-table tbody,
    .orders-table.mobile-card-table tbody {
        display: grid;
        width: 100%;
        gap: 8px;
        padding: 8px;
    }

    .mobile-card-table tr,
    .orders-table.mobile-card-table tr {
        display: grid;
        width: 100%;
        min-width: 0;
        gap: 0;
        border: 1px solid #e4e7ec;
        border-radius: 10px;
        background: #fff;
        padding: 10px 12px;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
    }

    .mobile-card-table tbody tr:nth-child(even),
    .mobile-card-table tbody tr:hover,
    .orders-table.mobile-card-table tbody tr:nth-child(even),
    .orders-table.mobile-card-table tbody tr:hover {
        background: #fff;
    }

    .mobile-card-table td,
    .mobile-card-table td:nth-child(n),
    .orders-table.mobile-card-table td,
    .orders-table.mobile-card-table td:nth-child(n) {
        display: grid;
        grid-template-columns: minmax(74px, 30%) minmax(0, 1fr);
        align-items: start;
        width: 100%;
        min-width: 0;
        gap: 10px;
        border: 0;
        border-top: 1px solid #eef2f6;
        padding: 7px 0;
        overflow: visible;
        white-space: normal;
        text-align: left;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }

    .mobile-card-table td:first-child,
    .orders-table.mobile-card-table td:first-child {
        border-top: 0;
    }

    .mobile-card-table td::before,
    .orders-table.mobile-card-table td::before {
        content: attr(data-label);
        color: #667085;
        font-weight: 800;
        line-height: 1.5;
    }

    .mobile-card-table td[data-label="操作"],
    .orders-table.mobile-card-table td[data-label="操作"] {
        grid-template-columns: 1fr;
        padding-top: 10px;
    }

    .mobile-card-table td[data-label="操作"]::before,
    .orders-table.mobile-card-table td[data-label="操作"]::before {
        display: none;
    }

    .mobile-card-table .row-actions,
    .mobile-card-table .home-invoice-row-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .mobile-card-table .row-actions .button,
    .mobile-card-table .home-invoice-row-actions .button,
    .mobile-card-table .home-invoice-row-actions a {
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }

    .clients-table td[data-label="取引先名"],
    .services-table td[data-label="サービス名"],
    .home-misoca-invoice-table td[data-label="請求書番号"],
    .misoca-client-table td[data-label="取引先"] {
        font-weight: 800;
    }

    .misoca-manual-table td {
        grid-template-columns: 88px minmax(0, 1fr);
        align-items: center;
    }

    .misoca-manual-table td input {
        min-width: 0;
        width: 100%;
    }

    .misoca-manual-table td[data-label="操作"] .button {
        width: 100%;
    }

    .check-column input {
        width: 20px;
        min-height: 20px;
    }

    /* Existing invoice workflow */
    .invoice-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .invoice-tab {
        flex: 0 0 auto;
        width: auto;
    }

    .invoice-controls {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .invoice-controls label:first-child,
    .invoice-control-wide,
    .invoice-controls .button {
        grid-column: auto;
    }

    .preview-toolbar,
    .dialog-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .preview-actions,
    .dialog-actions>div {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .preview-actions .button,
    .dialog-actions .button {
        width: 100%;
    }

    .invoice-preview-shell {
        overflow: hidden;
    }

    .invoice-preview {
        width: calc(100% - 16px);
        min-width: 0;
        min-height: 0;
        margin: 8px;
        padding: 18px 14px;
    }

    .invoice-title-row,
    .invoice-address,
    .invoice-total-row {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .invoice-meta {
        text-align: left;
    }

    .invoice-company.has-seal {
        grid-template-columns: minmax(0, 1fr) 64px;
    }

    .invoice-seal {
        width: 64px;
        height: 64px;
    }

    .invoice-preview th,
    .invoice-preview td {
        padding: 7px 5px;
    }

    dialog,
    #entry-dialog.order-entry-dialog,
    .invoice-dialog {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        margin: auto;
    }

    .dialog-card {
        gap: 14px;
        padding: 16px;
    }

    .invoice-dialog-card {
        padding: 0;
    }

    .invoice-dialog-body {
        max-height: calc(100vh - 170px);
    }

    #entry-dialog.order-entry-dialog .order-form-grid {
        grid-template-columns: 1fr;
    }

    #entry-dialog.order-entry-dialog .order-form-dates label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-money label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(4) {
        grid-column: auto;
    }
}

@media (max-width: 380px) {
    .workspace {
        padding-left: 8px;
        padding-right: 8px;
    }

    .metrics {
        gap: 6px;
    }

    .metric {
        padding: 10px;
    }

    .metric strong {}

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .home-invoice-actions {
        grid-template-columns: 1fr;
    }

    .home-invoice-actions>* {
        grid-column: auto !important;
    }

    .payment-method-card {
        grid-template-columns: 34px minmax(0, 1fr);
    }

    .payment-enabled {
        grid-column: 2;
        justify-self: start;
    }
}

/* =========================================================
   MOBILE FINAL — compact spreadsheet + stable dialogs
   2026-08-29
   ========================================================= */
@media screen and (max-width: 640px) {
    :root {}

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

    body {}

    .app-shell,
    .workspace,
    .view,
    .panel,
    .topbar,
    .topbar-title,
    .topbar-actions,
    .metrics,
    .panel-toolbar,
    .section-head,
    .misoca-layout,
    .misoca-card,
    .misoca-invoice-page,
    .misoca-invoice-page-card,
    .company-form,
    .settings-grid {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .workspace {
        margin: 0;
        padding: 12px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left));
        overflow-x: hidden;
    }

    .topbar {
        gap: 10px;
        margin: 0 0 12px;
    }

    .topbar h2 {}

    .topbar .eyebrow,
    .panel-copy,
    .result-count,
    .section-head p,
    .misoca-manual-head>div>span,
    .invoice-payment-note,
    .home-invoice-summary,
    .misoca-status-detail {}

    .topbar-actions {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 8px;
    }

    .search-box {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
        height: 44px;
    }

    #primary-action {
        grid-column: 1 / -1;
        width: 100%;
        min-height: 44px;
    }

    #export-button {
        display: none;
    }

    .mobile-panel-export {
        display: inline-flex;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 12px;
    }

    .metric {
        min-height: 55px;
        padding: 8px 12px;
    }

    .metric span {}

    .metric strong {
        line-height: 1.15;
        white-space: nowrap;
    }

    .panel {
        border-radius: 11px;
    }

    .panel-toolbar {
        min-height: 0;
        padding: 10px 12px;
        gap: 8px;
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .panel-toolbar>.panel-copy,
    .panel-toolbar>.segmented {
        flex: 1 1 100%;
    }

    .panel-toolbar-side {
        margin-left: auto;
    }

    .button {
        min-height: 40px;
        padding: 0 12px;
    }

    .button.compact {
        min-height: 32px;
        padding: 0 9px;
    }

    .segment,
    .invoice-tab,
    .status-pill,
    .scope-pill,
    .url-chip {}

    /* iOS Safari zooms focused controls below 16px. Keep UI text 14px,
     but form controls at 16px so the viewport never auto-zooms. */
    input,
    select,
    textarea {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0 !important;
        min-height: 44px;
        padding: 8px 10px;
        line-height: 1.3;
        box-sizing: border-box;
    }

    label,
    .field-block {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        line-height: 1.35;
    }

    textarea {
        resize: vertical;
    }

    input[type="date"],
    input[type="month"],
    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"] {
        inline-size: 100%;
        max-inline-size: 100%;
        min-inline-size: 0 !important;
    }

    input[type="date"]::-webkit-date-and-time-value,
    input[type="month"]::-webkit-date-and-time-value {
        min-width: 0;
        text-align: left;
    }

    .form-grid,
    .form-grid.two,
    .form-grid.three,
    #entry-dialog.order-entry-dialog .order-form-grid,
    .misoca-form-grid {
        grid-template-columns: 1fr;
    }

    .misoca-form-grid .misoca-wide,
    #entry-dialog.order-entry-dialog .order-form-dates label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-money label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(3),
    #entry-dialog.order-entry-dialog .order-form-status label:nth-child(4) {
        grid-column: auto;
    }

    /* Stable mobile entry modal: no horizontal flexing / rubber-band width. */
    dialog,
    #entry-dialog,
    #entry-dialog.order-entry-dialog,
    .invoice-dialog {
        box-sizing: border-box;
        width: calc(100% - 16px);
        max-width: calc(100% - 16px);
        min-width: 0;
        margin: auto;
        padding: 0;
        overflow: hidden;
    }

    #entry-dialog .dialog-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        max-height: calc(100dvh - 16px);
        padding: 16px;
        gap: 14px;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    #entry-dialog .dialog-head,
    #entry-dialog #form-fields,
    #entry-dialog .form-stack,
    #entry-dialog .form-grid,
    #entry-dialog .order-copy-panel,
    #entry-dialog .dialog-actions {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    #entry-dialog #form-fields,
    #entry-dialog .form-stack,
    #entry-dialog .form-grid {
        overflow-x: hidden;
    }

    #entry-dialog textarea {
        min-height: 96px;
    }

    #entry-dialog .order-copy-panel {
        align-items: stretch;
        flex-direction: column;
    }

    #entry-dialog .copy-actions {
        justify-content: flex-start;
    }

    #entry-dialog .copy-status {
        min-width: 0;
        text-align: left;
    }

    #entry-dialog .dialog-actions {
        position: sticky;
        bottom: -16px;
        z-index: 3;
        margin: 0 -16px -16px;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid #eaecf0;
        background: rgba(255, 255, 255, .98);
        backdrop-filter: blur(8px);
    }

    #entry-dialog .dialog-actions>div {
        min-width: 0;
        flex-wrap: wrap;
    }

    #entry-dialog .dialog-actions .button {
        min-width: 0;
    }

    .invoice-dialog-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .invoice-dialog-body {
        max-height: calc(100dvh - 170px);
        overflow-x: hidden;
    }

    /* Spreadsheet lists: page stays 100% width; only the grid scrolls horizontally. */
    .table-wrap,
    .table-wrap:has(> .mobile-card-table),
    #clients-list.table-wrap,
    #services-list.table-wrap,
    #misoca-order-list.table-wrap,
    #misoca-client-list.table-wrap,
    #misoca-manual-items.table-wrap,
    #home-misoca-invoice-list.table-wrap,
    .home-invoice-table-wrap,
    #issued-invoices,
    #unpaid-invoices,
    #paid-invoices,
    #invoice-order-list,
    #manual-invoice-items {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto !important;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        touch-action: pan-x pan-y;
    }

    .mobile-card-table,
    .orders-table.mobile-card-table,
    .clients-table.mobile-card-table,
    .services-table.mobile-card-table,
    .home-misoca-invoice-table.mobile-card-table,
    .misoca-order-table.mobile-card-table,
    .misoca-client-table.mobile-card-table,
    .misoca-manual-table.mobile-card-table,
    #issued-invoices .invoice-table,
    #unpaid-invoices .invoice-table,
    #paid-invoices .invoice-table,
    #invoice-order-list .invoice-table,
    .manual-invoice-table {
        display: table !important;
        width: max-content !important;
        min-width: 100% !important;
        max-width: none !important;
        border-collapse: separate;
        border-spacing: 0;
        table-layout: auto !important;
        background: #fff;
    }

    .mobile-card-table thead,
    .orders-table.mobile-card-table thead,
    #issued-invoices .invoice-table thead,
    #unpaid-invoices .invoice-table thead,
    #paid-invoices .invoice-table thead,
    #invoice-order-list .invoice-table thead,
    .manual-invoice-table thead {
        display: table-header-group !important;
    }

    .mobile-card-table tbody,
    .orders-table.mobile-card-table tbody,
    #issued-invoices .invoice-table tbody,
    #unpaid-invoices .invoice-table tbody,
    #paid-invoices .invoice-table tbody,
    #invoice-order-list .invoice-table tbody,
    .manual-invoice-table tbody {
        display: table-row-group !important;
        width: auto;
        padding: 0;
    }

    .mobile-card-table tr,
    .orders-table.mobile-card-table tr,
    #issued-invoices .invoice-table tr,
    #unpaid-invoices .invoice-table tr,
    #paid-invoices .invoice-table tr,
    #invoice-order-list .invoice-table tr,
    .manual-invoice-table tr {
        display: table-row !important;
        width: auto;
        border: 0;
        border-radius: 0;
        padding: 0;
        background: transparent;
        box-shadow: none;
    }

    .mobile-card-table th,
    .mobile-card-table td,
    .mobile-card-table td:nth-child(n),
    .orders-table.mobile-card-table th,
    .orders-table.mobile-card-table td,
    .orders-table.mobile-card-table td:nth-child(n),
    #issued-invoices .invoice-table th,
    #issued-invoices .invoice-table td,
    #unpaid-invoices .invoice-table th,
    #unpaid-invoices .invoice-table td,
    #paid-invoices .invoice-table th,
    #paid-invoices .invoice-table td,
    #invoice-order-list .invoice-table th,
    #invoice-order-list .invoice-table td,
    .manual-invoice-table th,
    .manual-invoice-table td,
    .manual-invoice-table td:nth-child(n) {
        display: table-cell !important;
        width: auto !important;
        max-width: none;
        min-width: 0;
        border-top: 0;
        border-right: 1px solid #e4e7ec;
        border-bottom: 1px solid #e4e7ec;
        padding: 7px 8px;
        overflow: hidden;
        white-space: nowrap;
        text-align: left;
        text-overflow: ellipsis;
        overflow-wrap: normal;
        vertical-align: middle;
        line-height: 1.25;
    }

    .mobile-card-table th,
    #issued-invoices .invoice-table th,
    #unpaid-invoices .invoice-table th,
    #paid-invoices .invoice-table th,
    #invoice-order-list .invoice-table th,
    .manual-invoice-table th {
        position: sticky;
        top: 0;
        z-index: 2;
        background: #f8f9fb;
        color: #344054;
        font-weight: 800;
    }

    .mobile-card-table th:last-child,
    .mobile-card-table td:last-child,
    #issued-invoices .invoice-table th:last-child,
    #issued-invoices .invoice-table td:last-child,
    #unpaid-invoices .invoice-table th:last-child,
    #unpaid-invoices .invoice-table td:last-child,
    #paid-invoices .invoice-table th:last-child,
    #paid-invoices .invoice-table td:last-child,
    #invoice-order-list .invoice-table th:last-child,
    #invoice-order-list .invoice-table td:last-child,
    .manual-invoice-table th:last-child,
    .manual-invoice-table td:last-child {
        border-right: 0;
    }

    .mobile-card-table td::before,
    .orders-table.mobile-card-table td::before,
    #issued-invoices .invoice-table td::before,
    #unpaid-invoices .invoice-table td::before,
    #paid-invoices .invoice-table td::before,
    #invoice-order-list .invoice-table td::before,
    .manual-invoice-table td::before {
        display: none !important;
        content: none !important;
    }

    .mobile-card-table tbody tr:nth-child(even),
    .orders-table.mobile-card-table tbody tr:nth-child(even),
    #issued-invoices .invoice-table tbody tr:nth-child(even),
    #unpaid-invoices .invoice-table tbody tr:nth-child(even),
    #paid-invoices .invoice-table tbody tr:nth-child(even),
    #invoice-order-list .invoice-table tbody tr:nth-child(even),
    .manual-invoice-table tbody tr:nth-child(even) {
        background: #f9fafb;
    }

    .mobile-card-table tbody tr:hover,
    .orders-table.mobile-card-table tbody tr:hover,
    #issued-invoices .invoice-table tbody tr:hover,
    #unpaid-invoices .invoice-table tbody tr:hover,
    #paid-invoices .invoice-table tbody tr:hover,
    #invoice-order-list .invoice-table tbody tr:hover,
    .manual-invoice-table tbody tr:hover {
        background: #f5f7ff;
    }

    /* Compact, intentional column widths. */
    .orders-table th:nth-child(1),
    .orders-table td:nth-child(1) {
        min-width: 88px;
    }

    .orders-table th:nth-child(2),
    .orders-table td:nth-child(2) {
        min-width: 128px;
    }

    .orders-table th:nth-child(3),
    .orders-table td:nth-child(3) {
        width: 200px !important;
        min-width: 200px;
        max-width: 200px;
    }

    .orders-table th:nth-child(4),
    .orders-table td:nth-child(4) {
        min-width: 150px;
        max-width: 190px;
    }

    .orders-table th:nth-child(5),
    .orders-table td:nth-child(5) {
        min-width: 120px;
    }

    .orders-table th:nth-child(6),
    .orders-table td:nth-child(6) {
        min-width: 72px;
    }

    .orders-table th:nth-child(7),
    .orders-table td:nth-child(7) {
        min-width: 72px;
    }

    .orders-table th:nth-child(8),
    .orders-table td:nth-child(8) {
        min-width: 52px;
    }

    .orders-table th:nth-child(9),
    .orders-table td:nth-child(9) {
        min-width: 96px;
    }

    .orders-table th:nth-child(10),
    .orders-table td:nth-child(10) {
        min-width: 76px;
    }

    .clients-table th:nth-child(1),
    .clients-table td:nth-child(1) {
        min-width: 138px;
    }

    .clients-table th:nth-child(2),
    .clients-table td:nth-child(2) {
        min-width: 96px;
    }

    .clients-table th:nth-child(3),
    .clients-table td:nth-child(3) {
        min-width: 158px;
    }

    .clients-table th:nth-child(4),
    .clients-table td:nth-child(4) {
        min-width: 116px;
    }

    .clients-table th:nth-child(5),
    .clients-table td:nth-child(5) {
        min-width: 150px;
        max-width: 190px;
    }

    .clients-table th:nth-child(6),
    .clients-table td:nth-child(6) {
        min-width: 112px;
        max-width: 160px;
    }

    .clients-table th:nth-child(7),
    .clients-table td:nth-child(7) {
        min-width: 128px;
        max-width: 170px;
    }

    .clients-table th:nth-child(8),
    .clients-table td:nth-child(8) {
        min-width: 64px;
    }

    .services-table th:nth-child(1),
    .services-table td:nth-child(1) {
        min-width: 86px;
    }

    .services-table th:nth-child(2),
    .services-table td:nth-child(2) {
        min-width: 120px;
    }

    .services-table th:nth-child(3),
    .services-table td:nth-child(3) {
        min-width: 140px;
    }

    .services-table th:nth-child(4),
    .services-table td:nth-child(4) {
        min-width: 160px;
        max-width: 210px;
    }

    .services-table th:nth-child(5),
    .services-table td:nth-child(5) {
        min-width: 92px;
    }

    .services-table th:nth-child(6),
    .services-table td:nth-child(6) {
        min-width: 58px;
    }

    .services-table th:nth-child(7),
    .services-table td:nth-child(7) {
        min-width: 64px;
    }

    .home-misoca-invoice-table th:nth-child(1),
    .home-misoca-invoice-table td:nth-child(1) {
        min-width: 142px;
    }

    .home-misoca-invoice-table th:nth-child(2),
    .home-misoca-invoice-table td:nth-child(2) {
        min-width: 88px;
    }

    .home-misoca-invoice-table th:nth-child(3),
    .home-misoca-invoice-table td:nth-child(3) {
        min-width: 130px;
    }

    .home-misoca-invoice-table th:nth-child(4),
    .home-misoca-invoice-table td:nth-child(4) {
        min-width: 88px;
    }

    .home-misoca-invoice-table th:nth-child(5),
    .home-misoca-invoice-table td:nth-child(5) {
        min-width: 100px;
    }

    .home-misoca-invoice-table th:nth-child(6),
    .home-misoca-invoice-table td:nth-child(6) {
        min-width: 76px;
    }

    .home-misoca-invoice-table th:nth-child(7),
    .home-misoca-invoice-table td:nth-child(7) {
        min-width: 190px;
    }

    .misoca-order-table th:nth-child(1),
    .misoca-order-table td:nth-child(1) {
        min-width: 36px;
        width: 36px !important;
    }

    .misoca-order-table th:nth-child(2),
    .misoca-order-table td:nth-child(2) {
        min-width: 88px;
    }

    .misoca-order-table th:nth-child(3),
    .misoca-order-table td:nth-child(3) {
        min-width: 130px;
    }

    .misoca-order-table th:nth-child(4),
    .misoca-order-table td:nth-child(4) {
        min-width: 150px;
        max-width: 190px;
    }

    .misoca-order-table th:nth-child(5),
    .misoca-order-table td:nth-child(5) {
        min-width: 58px;
    }

    .misoca-order-table th:nth-child(6),
    .misoca-order-table td:nth-child(6) {
        min-width: 100px;
    }

    .misoca-order-table th:nth-child(7),
    .misoca-order-table td:nth-child(7) {
        min-width: 104px;
    }

    .misoca-client-table th:nth-child(1),
    .misoca-client-table td:nth-child(1) {
        min-width: 140px;
    }

    .misoca-client-table th:nth-child(2),
    .misoca-client-table td:nth-child(2) {
        min-width: 100px;
    }

    .misoca-client-table th:nth-child(3),
    .misoca-client-table td:nth-child(3) {
        min-width: 168px;
    }

    .misoca-client-table th:nth-child(4),
    .misoca-client-table td:nth-child(4) {
        min-width: 152px;
    }

    .misoca-client-table th:nth-child(5),
    .misoca-client-table td:nth-child(5) {
        min-width: 92px;
    }

    .misoca-manual-table th:nth-child(1),
    .misoca-manual-table td:nth-child(1) {
        min-width: 160px;
    }

    .misoca-manual-table th:nth-child(2),
    .misoca-manual-table td:nth-child(2) {
        min-width: 180px;
    }

    .misoca-manual-table th:nth-child(3),
    .misoca-manual-table td:nth-child(3) {
        min-width: 72px;
    }

    .misoca-manual-table th:nth-child(4),
    .misoca-manual-table td:nth-child(4) {
        min-width: 110px;
    }

    .misoca-manual-table th:nth-child(5),
    .misoca-manual-table td:nth-child(5) {
        min-width: 104px;
    }

    .misoca-manual-table th:nth-child(6),
    .misoca-manual-table td:nth-child(6) {
        min-width: 60px;
    }

    #invoice-order-list .invoice-table th:nth-child(1),
    #invoice-order-list .invoice-table td:nth-child(1) {
        min-width: 36px;
        width: 36px !important;
    }

    #invoice-order-list .invoice-table th:nth-child(2),
    #invoice-order-list .invoice-table td:nth-child(2) {
        min-width: 88px;
    }

    #invoice-order-list .invoice-table th:nth-child(3),
    #invoice-order-list .invoice-table td:nth-child(3) {
        min-width: 130px;
    }

    #invoice-order-list .invoice-table th:nth-child(4),
    #invoice-order-list .invoice-table td:nth-child(4) {
        min-width: 160px;
    }

    #invoice-order-list .invoice-table th:nth-child(5),
    #invoice-order-list .invoice-table td:nth-child(5) {
        min-width: 58px;
    }

    #invoice-order-list .invoice-table th:nth-child(6),
    #invoice-order-list .invoice-table td:nth-child(6) {
        min-width: 100px;
    }

    .manual-invoice-table th:nth-child(1),
    .manual-invoice-table td:nth-child(1) {
        min-width: 160px;
    }

    .manual-invoice-table th:nth-child(2),
    .manual-invoice-table td:nth-child(2) {
        min-width: 180px;
    }

    .manual-invoice-table th:nth-child(3),
    .manual-invoice-table td:nth-child(3) {
        min-width: 72px;
    }

    .manual-invoice-table th:nth-child(4),
    .manual-invoice-table td:nth-child(4) {
        min-width: 110px;
    }

    .manual-invoice-table th:nth-child(5),
    .manual-invoice-table td:nth-child(5) {
        min-width: 104px;
    }

    .manual-invoice-table th:nth-child(6),
    .manual-invoice-table td:nth-child(6) {
        min-width: 60px;
    }

    #issued-invoices .invoice-table th:nth-child(1),
    #issued-invoices .invoice-table td:nth-child(1),
    #unpaid-invoices .invoice-table th:nth-child(1),
    #unpaid-invoices .invoice-table td:nth-child(1),
    #paid-invoices .invoice-table th:nth-child(1),
    #paid-invoices .invoice-table td:nth-child(1) {
        min-width: 36px;
        width: 36px !important;
    }

    #issued-invoices .invoice-table th:nth-child(2),
    #issued-invoices .invoice-table td:nth-child(2),
    #unpaid-invoices .invoice-table th:nth-child(2),
    #unpaid-invoices .invoice-table td:nth-child(2),
    #paid-invoices .invoice-table th:nth-child(2),
    #paid-invoices .invoice-table td:nth-child(2) {
        min-width: 138px;
    }

    #issued-invoices .invoice-table th:nth-child(3),
    #issued-invoices .invoice-table td:nth-child(3),
    #unpaid-invoices .invoice-table th:nth-child(3),
    #unpaid-invoices .invoice-table td:nth-child(3),
    #paid-invoices .invoice-table th:nth-child(3),
    #paid-invoices .invoice-table td:nth-child(3) {
        min-width: 88px;
    }

    #issued-invoices .invoice-table th:nth-child(4),
    #issued-invoices .invoice-table td:nth-child(4),
    #unpaid-invoices .invoice-table th:nth-child(4),
    #unpaid-invoices .invoice-table td:nth-child(4),
    #paid-invoices .invoice-table th:nth-child(4),
    #paid-invoices .invoice-table td:nth-child(4) {
        min-width: 130px;
    }

    #issued-invoices .invoice-table th:nth-child(5),
    #issued-invoices .invoice-table td:nth-child(5),
    #unpaid-invoices .invoice-table th:nth-child(5),
    #unpaid-invoices .invoice-table td:nth-child(5),
    #paid-invoices .invoice-table th:nth-child(5),
    #paid-invoices .invoice-table td:nth-child(5) {
        min-width: 152px;
    }

    #issued-invoices .invoice-table th:nth-child(6),
    #issued-invoices .invoice-table td:nth-child(6),
    #unpaid-invoices .invoice-table th:nth-child(6),
    #unpaid-invoices .invoice-table td:nth-child(6),
    #paid-invoices .invoice-table th:nth-child(6),
    #paid-invoices .invoice-table td:nth-child(6) {
        min-width: 58px;
    }

    #issued-invoices .invoice-table th:nth-child(7),
    #issued-invoices .invoice-table td:nth-child(7),
    #unpaid-invoices .invoice-table th:nth-child(7),
    #unpaid-invoices .invoice-table td:nth-child(7),
    #paid-invoices .invoice-table th:nth-child(7),
    #paid-invoices .invoice-table td:nth-child(7) {
        min-width: 104px;
    }

    #issued-invoices .invoice-table th:nth-child(8),
    #issued-invoices .invoice-table td:nth-child(8),
    #unpaid-invoices .invoice-table th:nth-child(8),
    #unpaid-invoices .invoice-table td:nth-child(8),
    #paid-invoices .invoice-table th:nth-child(8),
    #paid-invoices .invoice-table td:nth-child(8) {
        min-width: 82px;
    }

    #issued-invoices .invoice-table th:nth-child(9),
    #issued-invoices .invoice-table td:nth-child(9),
    #unpaid-invoices .invoice-table th:nth-child(9),
    #unpaid-invoices .invoice-table td:nth-child(9),
    #paid-invoices .invoice-table th:nth-child(9),
    #paid-invoices .invoice-table td:nth-child(9) {
        min-width: 230px;
    }

    .check-column,
    .mobile-card-table .check-column {
        min-width: 36px !important;
        width: 36px !important;
        text-align: center !important;
    }

    .check-column input,
    .invoice-table input[type="checkbox"],
    .mobile-card-table input[type="checkbox"] {
        display: inline-block;
        width: 18px !important;
        height: 18px;
        min-width: 18px !important;
        min-height: 18px;
        padding: 0;
    }

    .mobile-card-table .row-actions,
    .mobile-card-table .home-invoice-row-actions,
    #issued-invoices .invoice-actions,
    #unpaid-invoices .invoice-actions,
    #paid-invoices .invoice-actions {
        display: flex;
        width: auto;
        min-width: 0;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 4px;
    }

    .table-wrap .button,
    .mobile-card-table .row-actions .button,
    .mobile-card-table .home-invoice-row-actions .button,
    .mobile-card-table .home-invoice-row-actions a,
    #issued-invoices .invoice-actions .button,
    #unpaid-invoices .invoice-actions .button,
    #paid-invoices .invoice-actions .button,
    .manual-invoice-table .button {
        width: auto !important;
        min-width: 0;
        min-height: 30px;
        padding: 0 8px;
        white-space: nowrap;
    }

    /* Table form fields remain 16px to prevent iOS focus zoom. */
    .misoca-manual-table input,
    .manual-invoice-table input,
    .mobile-card-table input:not([type="checkbox"]),
    .mobile-card-table select {
        min-width: 0 !important;
        min-height: 38px;
        padding: 6px 8px;
    }

    .misoca-manual-table td input,
    .manual-invoice-table td input {
        width: 100%;
    }

    .invoice-list-toolbar {
        display: flex;
        width: max-content;
        min-width: 100%;
        padding: 8px;
    }

    .invoice-list-toolbar .button {}

    .home-invoice-table-wrap {
        margin: 0;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }
}

@media screen and (max-width: 380px) {
    .workspace {
        padding-left: 8px;
        padding-right: 8px;
    }

    .metric strong {}
}

/* =========================================================
   MOBILE COMPACT TYPOGRAPHY + 3-COLUMN DIALOG ACTIONS
   2026-08-29
   ========================================================= */
@media screen and (max-width: 640px) {
    :root {}

    body {
        line-height: 1.45;
    }

    .topbar h2 {
        line-height: 1.2;
    }

    .topbar .eyebrow,
    .panel-copy,
    .result-count,
    .section-head p,
    .misoca-manual-head>div>span,
    .invoice-payment-note,
    .home-invoice-summary,
    .misoca-status-detail,
    label,
    .field-block {}

    .metric span {}

    .metric strong {}

    .button {
        min-height: 38px;
        padding: 0 10px;
        line-height: 1.2;
    }

    .button.compact {
        min-height: 30px;
        padding: 0 8px;
    }

    .segment,
    .invoice-tab,
    .status-pill,
    .scope-pill,
    .url-chip {}

    .mobile-card-table th,
    #issued-invoices .invoice-table th,
    #unpaid-invoices .invoice-table th,
    #paid-invoices .invoice-table th,
    #invoice-order-list .invoice-table th,
    .manual-invoice-table th {}

    .mobile-card-table td,
    .mobile-card-table td:nth-child(n),
    .orders-table.mobile-card-table td,
    .orders-table.mobile-card-table td:nth-child(n),
    #issued-invoices .invoice-table td,
    #unpaid-invoices .invoice-table td,
    #paid-invoices .invoice-table td,
    #invoice-order-list .invoice-table td,
    .manual-invoice-table td,
    .manual-invoice-table td:nth-child(n) {}

    /* Keep form controls at 16px to prevent iOS Safari focus zoom. */
    input,
    select,
    textarea,
    .misoca-manual-table input,
    .manual-invoice-table input,
    .mobile-card-table input:not([type="checkbox"]),
    .mobile-card-table select {}

    #entry-dialog .dialog-card {
        gap: 11px;
        padding: 12px;
    }

    #entry-dialog .dialog-head {
        gap: 8px;
    }

    #entry-dialog .dialog-head .eyebrow {}

    #entry-dialog .dialog-head h3 {
        line-height: 1.2;
    }

    #entry-dialog .dialog-actions {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: stretch !important;
        gap: 6px;
        margin: 0 -12px -12px;
        padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    }

    #entry-dialog .dialog-actions>div {
        display: contents !important;
    }

    #entry-dialog .dialog-actions .button {
        width: 100% !important;
        min-width: 0;
        min-height: 38px;
        padding: 0 6px;
        white-space: nowrap;
    }

    #entry-dialog textarea {
        min-height: 82px;
    }
}

@media screen and (max-width: 360px) {
    #entry-dialog .dialog-actions {
        gap: 5px;
    }

    #entry-dialog .dialog-actions .button {
        padding-left: 4px;
        padding-right: 4px;
    }
}

/* Typography note: all custom responsive font-size overrides were removed; original project sizes are used. */


/* =========================================================
   MOBILE HEADER COUNT + CSV — list actions live in header
   2026-08-29
   ========================================================= */
.mobile-header-tools {
    display: none;
}

@media screen and (max-width: 640px) {
    .topbar-title {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
    }

    .topbar-heading {
        flex: 1 1 auto;
        min-width: 0;
    }

    .topbar-heading .eyebrow,
    .topbar-heading h2 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-header-tools {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: flex-end;
        gap: 6px;
        margin-left: auto;
    }

    .mobile-header-tools[hidden],
    .mobile-header-count[hidden],
    .mobile-header-export[hidden] {
        display: none !important;
    }

    .mobile-header-count {
        display: inline-flex;
        align-items: center;
        min-height: 30px;
        color: var(--muted);
        font-size: 12px;
        line-height: 1;
        white-space: nowrap;
    }

    .mobile-header-export.button {
        width: auto !important;
        min-width: 50px;
        min-height: 34px;
        height: 34px;
        padding: 0 10px;
        border-radius: 8px;
        font-size: 13px;
        line-height: 1;
    }

    /* 件数・CSVはスマホでは各パネル内に重複表示しない */
    .panel-toolbar-side .result-count,
    .mobile-panel-export {
        display: none !important;
    }
}

@media screen and (max-width: 380px) {
    .topbar-title {
        gap: 8px;
    }

    .mobile-header-tools {
        gap: 4px;
    }

    .mobile-header-count {
        font-size: 11px;
    }

    .mobile-header-export.button {
        min-width: 46px;
        padding: 0 8px;
        font-size: 12px;
    }
}




a.button.secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1;
}
/* =========================================================
   DESKTOP FIXED SIDEBAR
   Left navigation stays fixed; only the workspace scrolls.
   ========================================================= */
@media screen and (min-width: 981px) {
    .app-shell {
        display: block;
        min-height: 100vh;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 30;
        width: 268px;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .workspace {
        width: calc(100% - 268px);
        margin-left: 268px;
    }
}


/* ===== Dashboard calendar ===== */
.calendar-card {
    margin: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    overflow: hidden;
}

.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--line);
}

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

.calendar-heading .eyebrow {
    margin: 0 0 4px;
}

.calendar-title-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.calendar-title-row h3 {
    margin: 0;
    font-size: 1.05rem;
}

#calendar-month-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.calendar-actions,
.calendar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.calendar-nav-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    font-size: 1.35rem;
    font-weight: 800;
}

.calendar-today-button {
    min-height: 38px;
}

.calendar-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(260px, 0.7fr);
    min-width: 0;
}

.calendar-month-wrap {
    min-width: 0;
    padding: 12px;
    border-right: 1px solid var(--line);
}

.calendar-weekdays,
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    background: #f8fafc;
}

.calendar-weekdays span {
    padding: 8px 4px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 900;
    text-align: center;
}

.calendar-weekdays .sun { color: #d04a4a; }
.calendar-weekdays .sat { color: #3179b9; }

.calendar-grid {
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
}

.calendar-day {
    position: relative;
    display: grid;
    align-content: start;
    gap: 5px;
    min-width: 0;
    min-height: 94px;
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #fff;
    padding: 7px;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.calendar-day:hover {
    background: #f8fbff;
}

.calendar-day:focus-visible {
    z-index: 2;
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.calendar-day.is-outside {
    background: #fafbfc;
    color: #a8b0ba;
}

.calendar-day.is-selected {
    box-shadow: inset 0 0 0 2px var(--accent);
    background: #f5faff;
}

.calendar-day-number {
    display: inline-grid;
    place-items: center;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    font-size: 0.78rem;
    font-weight: 900;
}

.calendar-day.is-today .calendar-day-number {
    background: var(--accent);
    color: #fff;
}

.calendar-day-events {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.calendar-event-chip {
    overflow: hidden;
    border-radius: 4px;
    padding: 3px 5px;
    font-size: 0.66rem;
    font-weight: 800;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event-chip.manual { background: #e8f4ff; color: #1263a3; }
.calendar-event-chip.delivery { background: #e9f8f1; color: #287a57; }
.calendar-event-chip.invoice { background: #fff3df; color: #9a6418; }
.calendar-event-more { color: var(--muted); font-size: 0.66rem; font-weight: 800; }
.calendar-mobile-dots { display: none; }

.calendar-agenda {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 12px;
    background: #fbfcfe;
}

.calendar-agenda-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.calendar-agenda-head > div {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.calendar-agenda-head span {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
}

.calendar-agenda-head strong {
    font-size: 0.86rem;
    line-height: 1.35;
}

.calendar-agenda-list {
    display: grid;
    gap: 7px;
}

.calendar-agenda-item {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px;
    border: 1px solid var(--line);
    border-left-width: 4px;
    border-radius: 8px;
    background: #fff;
    padding: 9px;
}

.calendar-agenda-item.manual { border-left-color: #2589d9; }
.calendar-agenda-item.delivery { border-left-color: #3c9c73; }
.calendar-agenda-item.invoice { border-left-color: #d99a35; }

.calendar-agenda-time {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 900;
    white-space: nowrap;
}

.calendar-agenda-body {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.calendar-agenda-body strong {
    overflow-wrap: anywhere;
    font-size: 0.8rem;
    line-height: 1.4;
}

.calendar-agenda-body p,
.calendar-agenda-body span {
    margin: 0;
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.calendar-edit-button {
    width: auto;
    min-width: 44px;
    padding: 0 8px;
    font-size: 0.68rem;
    font-weight: 800;
}

.calendar-empty {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 22px 12px;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: center;
}

.calendar-notification-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: #f8fbfc;
}

.calendar-notification-bar[data-state="enabled"] {
    background: #edf8f4;
}

.calendar-notification-bar[data-state="error"],
.calendar-notification-bar[data-state="denied"] {
    background: #fff8ef;
}

.calendar-notification-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.calendar-notification-copy strong {
    font-size: 0.78rem;
}

.calendar-notification-copy span {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.45;
}

.calendar-notification-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.calendar-legend {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 8px 14px 11px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
}

.calendar-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.calendar-legend i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.calendar-legend i.manual { background: #2589d9; }
.calendar-legend i.delivery { background: #3c9c73; }
.calendar-legend i.invoice { background: #d99a35; }

.calendar-dialog-card {
    width: min(560px, calc(100vw - 28px));
}

.calendar-dialog-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 4px 0;
}

.calendar-dialog-fields .field small {
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.4;
}

.calendar-dialog-fields input[type="date"],
.calendar-dialog-fields input[type="time"] {
    position: relative;
    cursor: pointer;
}

.calendar-dialog-fields input[type="date"]::-webkit-calendar-picker-indicator,
.calendar-dialog-fields input[type="time"]::-webkit-calendar-picker-indicator {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    opacity: 0;
    cursor: pointer;
}

.calendar-field-wide {
    grid-column: 1 / -1;
}

.calendar-dialog-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calendar-dialog-spacer {
    flex: 1 1 auto;
}

@media (max-width: 980px) {
    .calendar-layout {
        grid-template-columns: 1fr;
    }
    .calendar-month-wrap {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
}

@media (max-width: 640px) {
    .calendar-card {
        margin: 8px;
        border-radius: 10px;
    }

    .calendar-head {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .calendar-actions {
        justify-content: space-between;
        width: 100%;
    }

    .calendar-actions > .button.primary {
        min-height: 40px;
    }

    .calendar-month-wrap {
        padding: 8px;
    }

    .calendar-weekdays span {
        padding: 6px 2px;
        font-size: 0.66rem;
    }

    .calendar-day {
        min-height: 52px;
        gap: 2px;
        padding: 4px 3px;
    }

    .calendar-day-number {
        width: 23px;
        height: 23px;
        font-size: 0.72rem;
    }

    .calendar-day-events {
        display: none;
    }

    .calendar-mobile-dots {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 7px;
    }

    .calendar-mobile-dots i {
        width: 5px;
        height: 5px;
        border-radius: 50%;
    }

    .calendar-mobile-dots i.manual { background: #2589d9; }
    .calendar-mobile-dots i.delivery { background: #3c9c73; }
    .calendar-mobile-dots i.invoice { background: #d99a35; }

    .calendar-agenda {
        padding: 10px;
    }

    .calendar-agenda-item {
        grid-template-columns: 54px minmax(0, 1fr) auto;
        gap: 6px;
        padding: 8px;
    }

    .calendar-legend {
        gap: 10px;
        padding: 8px 10px 10px;
    }

    .calendar-notification-bar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    .calendar-notification-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    #calendar-notification-test[hidden] + #calendar-notification-toggle {
        grid-column: 1 / -1;
    }

    .calendar-notification-actions .button {
        min-height: 40px;
    }

    .calendar-dialog-fields {
        grid-template-columns: 1fr;
    }

    .calendar-field-wide {
        grid-column: auto;
    }

    .calendar-dialog-actions {
        flex-wrap: wrap;
    }

    .calendar-dialog-actions .button {
        min-height: 44px;
    }
}

/* Admin password settings */
.settings-password-card {
    grid-column: 1 / -1;
    align-items: stretch;
}

.settings-password-copy {
    min-width: 220px;
    max-width: 360px;
}

.settings-password-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.settings-password-form label {
    display: grid;
    gap: 6px;
    min-width: 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.settings-password-form input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 0 10px;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
}

.settings-password-form input:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.settings-password-actions {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.settings-password-status {
    flex: 1;
    min-width: 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.45;
}

@media (max-width: 900px) {
    .settings-password-card {
        display: block;
    }

    .settings-password-copy {
        max-width: none;
        margin-bottom: 14px;
    }

    .settings-password-form {
        grid-template-columns: 1fr;
    }

    .settings-password-actions {
        grid-column: 1;
        display: grid;
        gap: 10px;
    }

    .settings-password-actions .button {
        width: 100%;
        min-height: 44px;
    }
}

/* =========================================================
   BUSINESS SWITCHER / MULTI-BUSINESS SETTINGS
   ========================================================= */
.business-switcher {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.business-switcher select {
    width: auto;
    min-width: 118px;
    max-width: 180px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--ink);
    padding: 0 30px 0 10px;
    font-weight: 800;
}

.business-settings-card {
    grid-column: 1 / -1;
    align-items: stretch;
}

.business-settings-copy {
    min-width: 220px;
    max-width: 380px;
}

.business-settings-form {
    display: grid;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.business-name-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 10px;
}

.business-name-fields label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.business-name-fields input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 0 10px;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
}

.business-settings-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    color: var(--muted);
    font-size: 0.82rem;
}

.business-settings-actions strong {
    color: var(--ink);
}

@media (max-width: 900px) {
    .business-settings-card {
        display: block;
    }

    .business-settings-copy {
        max-width: none;
        margin-bottom: 14px;
    }
}

@media screen and (max-width: 640px) {
    .topbar-business-switcher {
        margin-left: auto;
    }

    .topbar-business-switcher > span {
        display: none;
    }

    .business-switcher select {
        min-width: 92px;
        max-width: 118px;
        height: 34px;
        padding-left: 8px;
        padding-right: 24px;
        font-size: 13px;
    }

    .business-name-fields {
        grid-template-columns: 1fr;
    }

    .business-settings-actions {
        display: grid;
        gap: 8px;
    }

    .business-settings-actions .button {
        width: 100%;
        min-height: 42px;
    }
}

@media screen and (max-width: 380px) {
    .business-switcher select {
        min-width: 82px;
        max-width: 96px;
        font-size: 12px;
    }
}

.sidebar-business-switcher {
    display: grid;
    gap: 6px;
}

.sidebar-business-switcher select {
    width: 100%;
    max-width: none;
}

@media screen and (max-width: 640px) {
    .topbar-business-switcher {
        display: none;
    }
}


/* Event order columns: cast, salary, and direct payment-status toggle. */
.event-business-active .orders-table {
    min-width: 1460px;
}

.orders-table th:nth-child(5),
.orders-table td:nth-child(5) {
    width: 150px;
}

.orders-table th:nth-child(6),
.orders-table td:nth-child(6) {
    width: 112px;
}

.orders-table th:nth-child(7),
.orders-table td:nth-child(7) {
    width: 106px;
}

.orders-table th:nth-child(8),
.orders-table td:nth-child(8),
.orders-table th:nth-child(9),
.orders-table td:nth-child(9) {
    width: 82px;
}

.orders-table th:nth-child(10),
.orders-table td:nth-child(10) {
    width: 64px;
}

.orders-table th:nth-child(11),
.orders-table td:nth-child(11) {
    width: 110px;
}

.orders-table th:nth-child(12),
.orders-table td:nth-child(12) {
    width: 90px;
}

.cast-payment-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    min-height: 28px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.cast-payment-toggle.is-paid {
    border-color: #b8dec8;
    background: #edf8f1;
    color: #197043;
}

.cast-payment-toggle.is-unpaid {
    border-color: #e2c9c3;
    background: #fff3f0;
    color: #a94432;
}

.cast-payment-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

@media screen and (max-width: 640px) {
    .orders-table.mobile-card-table .cast-payment-toggle {
        min-width: 76px;
        min-height: 32px;
    }
}

/* =========================================================
   LIST TABLE ALIGNMENT + COMPACT SPACING
   2026-09-23
   All list pages: left-align every column and reduce cell gutters.
   ========================================================= */
.table-wrap table th,
.table-wrap table td {
    text-align: left !important;
    padding: 5px 6px;
}

.table-wrap table .numeric,
.table-wrap table .check-column {
    text-align: left !important;
}

@media screen and (max-width: 640px) {
    .table-wrap table th,
    .table-wrap table td {
        padding: 5px 5px;
    }
}


/* =========================================================
   LIST TABLE EXTRA COMPACT TUNING
   2026-09-23
   Tighten list columns further across all pages.
   ========================================================= */
.table-wrap table th,
.table-wrap table td {
    padding: 4px 5px !important;
}

.table-wrap table th:first-child,
.table-wrap table td:first-child {
    padding-left: 8px !important;
}

.table-wrap table th:last-child,
.table-wrap table td:last-child {
    padding-right: 8px !important;
}

.data-table {
    min-width: 860px;
}

.orders-table {
    min-width: 980px;
}

.event-business-active .orders-table {
    min-width: 1320px;
}

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

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

.orders-table th:nth-child(3),
.orders-table td:nth-child(3) {
    width: 220px;
}

.orders-table th:nth-child(4),
.orders-table td:nth-child(4) {
    width: 130px;
}

.orders-table th:nth-child(5),
.orders-table td:nth-child(5) {
    width: 100px;
}

.orders-table th:nth-child(6),
.orders-table td:nth-child(6) {
    width: 96px;
}

.orders-table th:nth-child(7),
.orders-table td:nth-child(7),
.orders-table th:nth-child(8),
.orders-table td:nth-child(8),
.orders-table th:nth-child(9),
.orders-table td:nth-child(9) {
    width: 74px;
}

.orders-table th:nth-child(10),
.orders-table td:nth-child(10) {
    width: 52px;
}

.orders-table th:nth-child(11),
.orders-table td:nth-child(11) {
    width: 96px;
}

.orders-table th:nth-child(12),
.orders-table td:nth-child(12) {
    width: 84px;
}

.services-table {
    min-width: 860px;
}

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

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

.services-table th:nth-child(5),
.services-table td:nth-child(5),
.services-table th:nth-child(6),
.services-table td:nth-child(6) {
    width: 84px;
}

.services-table th:nth-child(7),
.services-table td:nth-child(7) {
    width: 68px;
}

.clients-table {
    min-width: 1120px;
}

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

.clients-table th:nth-child(2),
.clients-table td:nth-child(2),
.clients-table th:nth-child(4),
.clients-table td:nth-child(4) {
    width: 120px;
}

.clients-table th:nth-child(3),
.clients-table td:nth-child(3) {
    width: 168px;
}

.clients-table th:nth-child(7),
.clients-table td:nth-child(7) {
    width: 150px;
}

.clients-table th:nth-child(8),
.clients-table td:nth-child(8) {
    width: 68px;
}

.status-pill,
.cast-payment-toggle,
.url-chip,
.scope-pill {
    min-width: 0;
    padding-left: 8px;
    padding-right: 8px;
}

.status-pill {
    min-height: 20px;
}

.cast-payment-toggle {
    min-height: 26px;
}

.row-actions {
    gap: 4px;
}

@media screen and (max-width: 640px) {
    .table-wrap table th,
    .table-wrap table td {
        padding: 4px 4px !important;
    }

    .table-wrap table th:first-child,
    .table-wrap table td:first-child,
    .table-wrap table th:last-child,
    .table-wrap table td:last-child {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }
}


/* イベント事業専用メニュー */
.event-companion-nav {
    display: none;
}

body.event-business-active .event-companion-nav {
    display: grid;
}

/* Keep event amounts beside cast salary; match the reordered column widths. */
body.event-business-active .orders-table th:nth-child(7),
body.event-business-active .orders-table td:nth-child(7) { width: 96px; }
body.event-business-active .orders-table th:nth-child(10),
body.event-business-active .orders-table td:nth-child(10) { width: 74px; }
body.event-business-active .orders-table th:nth-child(11),
body.event-business-active .orders-table td:nth-child(11) { width: 52px; }

/* Event business HOME: show only dates with scheduled items. */
.calendar-card.is-list-view .calendar-layout { display: none; }
.calendar-month-list { display: grid; gap: 18px; }
.calendar-month-list[hidden] { display: none; }
.calendar-list-day h4 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 8px;
    font-size: 0.9rem;
}
.calendar-list-day h4 span { color: var(--muted); font-size: 0.75rem; font-weight: 500; }
.calendar-list-day.is-today h4 time { color: #2589d9; }
.calendar-month-list .calendar-agenda-item { padding: 12px; }

@media (min-width: 1100px) {
    .metrics.metrics-with-month-orders { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
