* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #1e293b;
    --muted: #64748b;
    --border: #dbe3ec;
    --border-strong: #c7d2df;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --focus: rgba(37, 99, 235, 0.2);
    --error: #dc2626;
    --success: #15803d;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Noto Sans JP", "Meiryo", "Yu Gothic", sans-serif;
    font-size: 14px;
}

[v-cloak] {
    display: none;
}

button,
input,
textarea {
    font: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.pageShell {
    width: min(1240px, calc(100% - 40px));
    margin: 0 auto;
    padding: 22px 0 42px;
}

.siteHeader {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.eyebrow {
    margin-bottom: 3px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
}

.siteHeader h1 {
    margin-bottom: 0;
    font-size: 25px;
}

.headerLinks {
    display: flex;
    align-items: center;
    gap: 4px;
}

.headerLinks a,
.headerLinks button {
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
}

.headerLinks a:hover,
.headerLinks button:hover {
    background: #eaf1ff;
    color: var(--primary);
}

.headerLinks form {
    margin: 0;
}

.maintenanceNav {
    display: flex;
    gap: 4px;
    margin-bottom: 28px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.maintenanceNav a {
    flex: 1;
    padding: 10px 14px;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.maintenanceNav a:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.maintenanceNav a.isActive {
    background: #eaf1ff;
    color: var(--primary);
}

.pageHeading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
}

.pageHeading h2 {
    margin-bottom: 4px;
    font-size: 22px;
}

.pageHeading p {
    margin-bottom: 0;
    color: var(--muted);
}

.summaryBadge,
.countBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 3px 10px;
    border-radius: 999px;
    background: #eaf1ff;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.primaryButton,
.secondaryButton,
.textButton,
.dangerButton {
    min-height: 38px;
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
}

.dangerButton {
    border: 1px solid #dc2626;
    background: #dc2626;
    color: #fff;
}

.dangerButton:hover:not(:disabled) {
    background: #b91c1c;
}

.primaryButton {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
}

.primaryButton:hover:not(:disabled) {
    background: var(--primary-hover);
}

.secondaryButton {
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
}

.secondaryButton:hover:not(:disabled),
.textButton:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.textButton {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
}

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

input[type="text"],
input[type="password"],
textarea {
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

input[type="text"],
input[type="password"] {
    min-height: 38px;
    padding: 6px 10px;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
    outline: none;
}

input[type="checkbox"] {
    accent-color: var(--primary);
}

.listPanel {
    overflow: hidden;
}

.listToolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-muted);
}

.filterField,
.listActions,
.checkLabel {
    display: flex;
    align-items: center;
}

.filterField {
    min-width: 0;
    flex: 1;
    gap: 9px;
}

.filterField > label:first-child {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.filterField input[type="text"] {
    width: min(360px, 100%);
}

.listActions {
    flex: 0 0 auto;
    gap: 10px;
}

.checkLabel {
    gap: 6px;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.themeList {
    height: calc(100vh - 300px);
    min-height: 440px;
    overflow: auto;
    padding: 14px 18px 20px;
}

.themeNode + .themeNode {
    margin-top: 5px;
}

.themeNode summary {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 39px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

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

.themeNode summary::before {
    content: "▶";
    color: var(--primary);
    font-size: 10px;
    transition: transform 0.12s ease;
}

.themeNode[open] summary::before {
    transform: rotate(90deg);
}

.themeNode summary:hover {
    background: #edf3fb;
}

.themeCounts {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 23px;
    margin-left: auto;
}

.themeNode summary .countBadge {
    min-height: 23px;
    padding: 2px 8px;
}

.countBadge.isDanger {
    background: #fee2e2;
    color: #b91c1c;
}

.themeNode ul,
.stockList {
    margin: 2px 0 8px;
    padding: 0 0 0 35px;
    list-style: none;
}

.themeNodeActions {
    display: flex;
    justify-content: flex-start;
    padding: 3px 8px 3px 35px;
}

.themeNodeActions a {
    padding: 5px 9px;
    border-radius: 5px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.themeNodeActions a:hover {
    background: #eaf1ff;
}

.themeNode li,
.stockList li {
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 4px;
}

.themeNode li:hover,
.stockList li:hover {
    background: var(--surface-muted);
}

.stockCode {
    flex: 0 0 48px;
    color: var(--primary);
    font-family: Consolas, monospace;
    font-weight: 700;
    text-decoration: none;
}

.stockCode:hover {
    color: var(--primary-hover);
}

.stockName {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stockName.isUnknown {
    color: #b45309;
    font-style: italic;
}

.emptyState {
    min-height: 240px;
    display: grid;
    place-items: center;
    color: var(--muted);
}

.bulkLayout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 18px;
    align-items: start;
}

.inputPanel,
.helpPanel,
.singleFormPanel,
.registeredStocksPanel {
    padding: 20px;
}

.inputPanel > label,
.fieldGroup > label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
}

.fieldLabelRow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
}

.fieldLabelRow > label:first-child {
    font-size: 13px;
    font-weight: 700;
}

.inputPanel textarea {
    width: 100%;
    min-height: 520px;
    resize: vertical;
    padding: 13px 14px;
    background: var(--surface-muted);
    font-family: Consolas, "Noto Sans JP", monospace;
    line-height: 1.75;
}

.formActions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

.formActions.alignLeft {
    justify-content: flex-start;
}

.helpPanel h3 {
    margin-bottom: 12px;
    font-size: 16px;
}

.helpPanel code {
    display: block;
    padding: 9px 10px;
    border-radius: 5px;
    background: #eef2f7;
    color: var(--text);
}

.helpPanel > ul {
    margin: 16px 0 0;
    padding-left: 20px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.8;
}

.resultBox {
    margin-top: 18px;
    padding: 11px 12px;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    background: #f0fdf4;
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.6;
}

.resultBox.isError {
    border-color: #fecaca;
    background: #fef2f2;
    color: var(--error);
}

.validationErrors {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--error);
    font-size: 12px;
    line-height: 1.7;
}

.singleLayout {
    display: grid;
    grid-template-columns: minmax(380px, 0.8fr) minmax(440px, 1.2fr);
    gap: 18px;
    align-items: start;
}

.fieldGroup + .fieldGroup {
    margin-top: 18px;
}

.fieldGroup > input {
    width: 100%;
}

.bulkCodeTextarea {
    width: 100%;
    min-height: calc(5 * 1.65em + 18px);
    resize: vertical;
    padding: 8px 10px;
    font-family: Consolas, "Noto Sans JP", monospace;
    line-height: 1.65;
}

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

.themeInputRow input {
    min-width: 0;
    flex: 1;
}

.clearThemeButton {
    flex: 0 0 auto;
}

.fieldHint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.stockLookup {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 48px;
    margin-top: 18px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-muted);
}

.stockLookup span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.stockLookup strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stockLookup.isError strong,
.errorText {
    color: var(--error);
}

.registeredStocksPanel {
    min-height: 440px;
}

.registeredStocksPanel > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 10px;
}

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

.registeredStocksPanel h3 {
    margin-bottom: 3px;
    font-size: 17px;
}

.registeredStocksPanel header p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 12px;
}

.registeredStocksPanel .emptyState {
    min-height: 330px;
}

.stockList {
    max-height: 520px;
    overflow: auto;
    padding-right: 10px;
    padding-left: 0;
    scrollbar-gutter: stable;
}

.stockList .stockName {
    flex: 1;
}

.trashButton {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: inline-grid;
    place-items: center;
    padding: 5px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.trashButton:hover:not(:disabled) {
    background: #fee2e2;
    color: var(--error);
}

.trashButton svg {
    width: 18px;
    height: 18px;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.deleteResult {
    margin-bottom: 10px;
    padding: 8px 10px;
    border-radius: 5px;
    background: #f0fdf4;
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
}

.deleteResult.isError {
    background: #fef2f2;
    color: var(--error);
}

.confirmOverlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.42);
}

.confirmDialog {
    width: min(420px, 100%);
    padding: 22px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.24);
}

.confirmDialog h3 {
    margin-bottom: 10px;
    font-size: 18px;
}

.confirmDialog p {
    margin-bottom: 20px;
    color: var(--muted);
    line-height: 1.7;
}

.confirmDialog p strong {
    margin-right: 5px;
    color: var(--text);
}

.confirmActions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.loginPage {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.loginPanel {
    width: min(420px, 100%);
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.1);
}

.loginPanel h1 {
    margin-bottom: 8px;
}

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

.loginForm {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 22px;
}

.loginForm label {
    font-size: 13px;
    font-weight: 700;
}

.backLink {
    display: inline-block;
    margin-top: 20px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

@media (max-width: 980px) {
    .pageShell {
        width: min(100% - 24px, 1240px);
    }

    .listToolbar,
    .listActions {
        align-items: flex-start;
        flex-direction: column;
    }

    .bulkLayout,
    .singleLayout {
        grid-template-columns: 1fr;
    }
}
