:root {
    --primary: #0B8F79;
    --primary-dark: #087565;
    --text: #111827;
    --secondary: #667085;
    --background: #F7F9F9;
    --border: #E2E8E8;
    --surface: #fff;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
select {
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
}
.is-hidden { display: none !important; }
.mesai-app { min-height: 100vh; padding: 48px 22px 72px; }
.mesai-shell { width: min(1180px, 100%); margin: 0 auto; }
.mesai-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
}
.mesai-kicker,
.panel-heading span,
.result-heading span,
.drawer-head span {
    display: block;
    margin: 0 0 8px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 760;
    letter-spacing: 0;
}
.mesai-topbar h1 {
    margin: 0;
    color: var(--text);
    font-size: clamp(42px, 7vw, 72px);
    font-weight: 820;
    line-height: .9;
    letter-spacing: 0;
}
.mesai-topbar p:not(.mesai-kicker) {
    max-width: 600px;
    margin: 16px 0 0;
    color: var(--secondary);
    font-size: 16px;
    line-height: 1.55;
}
.icon-button {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: #475467;
    cursor: pointer;
}
.icon-button:hover { border-color: rgba(11, 143, 121, .36); color: var(--primary); }
.settings-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(17, 24, 39, .16);
}
.settings-panel {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 21;
    display: grid;
    width: min(392px, calc(100vw - 28px));
    max-height: calc(100vh - 36px);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 38px rgba(17, 24, 39, .08);
}
.settings-head,
.settings-foot {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 18px;
}
.settings-head { border-bottom: 1px solid var(--border); }
.settings-foot { border-top: 1px solid var(--border); }
.settings-head span {
    display: block;
    margin-bottom: 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 760;
}
.settings-head h2 { margin: 0; font-size: 20px; letter-spacing: 0; }
.settings-head p { margin: 7px 0 0; color: var(--secondary); font-size: 13px; line-height: 1.45; }
.settings-head .icon-button { width: 36px; height: 36px; flex-basis: 36px; }
.settings-body { display: grid; gap: 1px; overflow: auto; padding: 6px 18px 12px; }
.settings-section {
    padding: 14px 0;
    border-bottom: 1px solid #EDF2F2;
}
.settings-section:last-child { border-bottom: 0; }
.settings-section h3 {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 14px;
    letter-spacing: 0;
}
.switch-row {
    display: flex;
    min-height: 38px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #34403E;
    font-size: 14px;
    font-weight: 650;
}
.switch-row input {
    width: 42px;
    height: 24px;
    flex: 0 0 42px;
    appearance: none;
    border: 1px solid #CBD8D7;
    border-radius: 999px;
    background: #EEF2F2;
    cursor: pointer;
}
.switch-row input::before {
    content: "";
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    border-radius: 50%;
    background: #fff;
    transition: transform .16s ease;
}
.switch-row input:checked {
    border-color: var(--primary);
    background: var(--primary);
}
.switch-row input:checked::before { transform: translateX(18px); }
.settings-hint {
    margin: 9px 0 0;
    color: #A44949;
    font-size: 13px;
    font-weight: 700;
}
.segmented {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(92px, 1fr));
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #F8FAFA;
}
.segmented button {
    min-height: 36px;
    border: 0;
    border-right: 1px solid var(--border);
    background: transparent;
    color: var(--secondary);
    cursor: pointer;
    font-weight: 760;
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: #fff; color: var(--primary); }
.settings-section details { color: var(--text); }
.settings-section summary {
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    font-weight: 760;
}
.definition-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
}
.definition-list div {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 10px;
}
.definition-list dt { color: var(--text); font-size: 13px; font-weight: 800; }
.definition-list dd { margin: 0; color: var(--secondary); font-size: 13px; line-height: 1.35; }
svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}
.workflow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 22px;
}
.step {
    display: flex;
    min-height: 46px;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: #7C8785;
    font-size: 14px;
    font-weight: 760;
}
.step strong {
    display: grid;
    width: 25px;
    height: 25px;
    place-items: center;
    border-radius: 50%;
    background: #EEF2F2;
    color: #667085;
    font-size: 12px;
}
.step.active {
    border-color: rgba(11, 143, 121, .2);
    color: var(--primary);
}
.step.active strong { background: var(--primary); color: #fff; }
.upload-card,
.panel,
.summary-grid article,
.detail-drawer {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}
.upload-card { margin-bottom: 16px; }
.upload-zone {
    position: relative;
    display: grid;
    min-height: 208px;
    place-items: center;
    align-content: center;
    gap: 16px;
    margin: 14px;
    border: 1px dashed #B7C8C6;
    border-radius: 8px;
    background: #FCFDFD;
    text-align: center;
}
.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}
.upload-zone.is-selected { border-color: rgba(11, 143, 121, .55); background: #F3FAF8; }
.upload-icon {
    display: grid;
    width: 56px;
    height: 56px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--primary);
}
.upload-icon svg { width: 29px; height: 29px; }
.upload-zone h2,
.panel-heading h2,
.result-heading h2,
.drawer-head h3 {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    letter-spacing: 0;
}
.upload-zone p { margin: 7px 0 0; color: var(--secondary); font-size: 14px; }
.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 16px;
    cursor: pointer;
    font-weight: 760;
    text-decoration: none;
}
.button-primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { border-color: var(--border); background: #fff; color: var(--text); }
.button-secondary:hover,
.button-ghost:hover,
.detail-button:hover { border-color: rgba(11, 143, 121, .28); color: var(--primary); }
.button-ghost { border-color: transparent; background: transparent; color: var(--secondary); }
.button.full { width: 100%; }
.button-large { min-width: 172px; min-height: 52px; font-size: 16px; }
.grid-two {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
    gap: 16px;
    margin-bottom: 16px;
}
.panel { overflow: hidden; }
.panel-heading,
.result-heading,
.drawer-head { padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-heading.spread {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.config-list { display: grid; gap: 1px; margin: 0; padding: 8px 22px 18px; }
.config-list > div {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    align-items: center;
    min-height: 42px;
}
.config-list dt { color: var(--secondary); font-size: 13px; }
.config-list dd { margin: 0; color: var(--text); font-size: 14px; font-weight: 680; }
.config-list select { width: min(100%, 260px); padding: 0 10px; }
.range-row { align-items: flex-start !important; padding: 8px 0; }
.range-selector {
    display: grid;
    grid-template-columns: repeat(4, minmax(72px, 1fr));
    gap: 8px;
}
.range-selector label { display: grid; gap: 5px; }
.range-selector span {
    color: var(--secondary);
    font-size: 11px;
    font-weight: 650;
}
.range-selector input {
    width: 100%;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0 10px;
    color: var(--text);
    font-weight: 760;
}
.month-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.month-selector select {
    width: 150px;
    padding: 0 10px;
}
.month-selector input {
    width: 92px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0 10px;
    color: var(--text);
    font-weight: 760;
}
.status-line {
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    background: #fff;
    color: var(--secondary);
    font-size: 14px;
    font-weight: 700;
}
.status-line[data-tone="success"] {
    border-color: rgba(11, 143, 121, .28);
    background: #F0FAF7;
    color: var(--primary-dark);
}
.status-line[data-tone="error"] {
    border-color: #F0C9C9;
    background: #FFF6F6;
    color: #A44949;
}
.config-panel > .button,
.detection-panel > .button { width: calc(100% - 44px); margin: 0 22px 22px; }
.detect-stats { display: grid; gap: 9px; padding: 18px 22px 12px; }
.detect-stats strong { color: var(--text); font-size: 15px; }
.shift-types { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 16px; }
.shift-types span {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 10px;
    color: #465552;
    font-size: 13px;
    font-weight: 700;
}
.warning-note {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0 22px 18px;
    border: 1px solid #F3DFC2;
    border-radius: 8px;
    padding: 12px;
    background: #FFFBF3;
    color: #946329;
    font-size: 13px;
    font-weight: 700;
}
.warning-note svg { width: 18px; height: 18px; }
.period-warning {
    margin: 0 22px 16px;
    border: 1px solid #E7B96F;
    border-radius: 8px;
    padding: 12px 14px;
    background: #FFF7E7;
    color: #7D4E12;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.45;
}
.analysis-notes {
    margin: 0 22px 16px;
    border: 1px solid #E7EEEE;
    border-radius: 8px;
    padding: 10px 12px;
    background: #FBFDFD;
}
.analysis-notes p {
    margin: 0;
    color: var(--secondary);
    font-size: 13px;
    line-height: 1.45;
}
.analysis-notes p + p { margin-top: 6px; }
.unknown-list {
    display: grid;
    gap: 6px;
    margin: -8px 22px 18px;
    padding: 0;
    list-style: none;
}
.unknown-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #F1E0E0;
    border-radius: 7px;
    padding: 8px 10px;
    background: #FFFAFA;
    color: #7F3F3F;
    font-size: 13px;
}
.unknown-list strong { font-variant-numeric: tabular-nums; }
.unknown-list span::before { content: "→ "; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; color: var(--secondary); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i,
.cell { display: inline-grid; place-items: center; border-radius: 6px; font-style: normal; font-weight: 800; }
.legend i { width: 24px; height: 24px; font-size: 11px; }
.sheet-wrap { width: 100%; overflow: auto; }
.sheet-table {
    width: 100%;
    min-width: 1040px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}
.sheet-table th,
.sheet-table td {
    width: 32px;
    min-width: 32px;
    height: 40px;
    border-right: 1px solid #EDF2F2;
    border-bottom: 1px solid #EDF2F2;
    background: #fff;
    color: #53615F;
    text-align: center;
    font-size: 12px;
}
.sheet-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #FAFCFC;
    color: var(--secondary);
    font-weight: 760;
}
.sheet-table th.day-working,
.sheet-table td.day-working {
    background: #FFFFFF;
}
.sheet-table thead th.day-working {
    background: #F8FBFB;
}
.sheet-table th.day-non-working,
.sheet-table td.day-non-working {
    background: #EEF2F2;
    color: #465250;
}
.sheet-table thead th.day-non-working {
    background: #DDE6E5;
    color: #2F3D3A;
}
.sheet-table .sticky-col {
    position: sticky;
    left: 0;
    z-index: 2;
    width: 156px;
    min-width: 156px;
    border-right-color: #D7E1E1;
    background: #fff;
    padding: 0 14px;
    color: var(--text);
    text-align: left;
    font-weight: 760;
}
.sheet-table thead .sticky-col { z-index: 4; background: #FAFCFC; }
.density-compact .grid-two,
.density-compact .results-layout,
.density-compact .summary-grid { gap: 10px; }
.density-compact .sheet-table th,
.density-compact .sheet-table td {
    height: 32px;
    font-size: 11px;
}
.density-compact .sheet-table .sticky-col { padding: 0 10px; }
.density-compact .result-table th,
.density-compact .result-table td { padding: 10px 12px; }
.density-compact .week-list article { padding: 12px; }
.cell { width: 27px; height: 25px; font-size: 11px; }
.density-compact .cell { width: 26px; height: 22px; font-size: 10px; }
.cell i {
    margin-left: 1px;
    color: inherit;
    font-size: 10px;
    font-style: normal;
    line-height: 1;
    opacity: .72;
}
.cell-8 { background: #F3F6F6; color: #4D5C5A; }
.cell-16 { background: #EEF3F6; color: #526878; }
.cell-24 { background: #EAF6F3; color: #167466; }
.cell-nc { background: #F1F4F4; color: #6A7472; }
.cell-yi { background: #FFF6E6; color: #8C641F; }
.cell-r { background: #FCEEEE; color: #A44949; }
.cell-unknown { background: #F6EDED; color: #7F3F3F; }
.calculate-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 22px;
    border-top: 1px solid var(--border);
}
.calculate-row p { margin: 0; color: var(--secondary); font-size: 14px; }
.result-view { margin-top: 28px; }
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 16px 0;
}
.summary-grid article { min-height: 112px; padding: 20px; }
.summary-grid span { display: block; color: var(--secondary); font-size: 13px; }
.summary-grid strong { display: block; margin-top: 10px; color: var(--text); font-size: 25px; letter-spacing: 0; }
.results-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 310px;
    gap: 16px;
    align-items: start;
}
.results-layout.drawer-collapsed { grid-template-columns: 1fr; }
.table-scroll { overflow: auto; }
.result-table { width: 100%; min-width: 760px; border-collapse: collapse; white-space: nowrap; }
.result-table th,
.result-table td { padding: 14px 16px; border-bottom: 1px solid #EDF2F2; text-align: left; font-size: 14px; }
.result-table th { background: #FAFCFC; color: var(--secondary); font-size: 12px; font-weight: 760; }
.result-table tr.selected td { background: #F4FAF8; }
.result-table td:not(:first-child),
.result-table th:not(:first-child) { text-align: right; }
.result-table td:last-child,
.result-table th:last-child { text-align: right; }
.detail-button {
    min-height: 32px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0 10px;
    background: #fff;
    color: #344054;
    cursor: pointer;
    font-size: 13px;
    font-weight: 760;
}
.detail-drawer { overflow: hidden; }
.detail-drawer.is-collapsed { display: none; }
.drawer-head {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    background: #fff;
}
.drawer-head .detail-close { width: 36px; height: 36px; flex-basis: 36px; }
.details-panel { margin-top: 16px; }
.rules-copy {
    display: grid;
    gap: 8px;
    padding: 18px 22px;
}
.rules-copy p {
    margin: 0;
    color: var(--secondary);
    font-size: 14px;
    line-height: 1.55;
}
.week-list { display: grid; gap: 10px; padding: 14px; }
.week-list article { border: 1px solid #EDF2F2; border-radius: 8px; padding: 13px; background: #FCFDFD; }
.week-list strong { display: block; margin-bottom: 11px; font-size: 14px; }
.week-list dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px 12px; margin: 0; }
.week-list div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.week-list dt { color: var(--secondary); font-size: 12px; }
.week-list dd { margin: 0; color: var(--text); font-size: 13px; font-weight: 800; }
.bottom-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.export-menu {
    position: relative;
    display: inline-flex;
}
.export-options {
    position: absolute;
    z-index: 8;
    left: 0;
    bottom: calc(100% + 8px);
    display: grid;
    min-width: 190px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 6px;
}
.export-options button {
    min-height: 38px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    padding: 0 10px;
    text-align: left;
    font-weight: 720;
}
.export-options button:hover,
.export-options button:focus-visible {
    background: #F0FAF7;
    color: var(--primary);
    outline: none;
}
.empty-result {
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 8px 8px;
    padding: 26px 22px;
    background: #fff;
}
.empty-result p {
    margin: 0;
    color: var(--secondary);
    font-size: 15px;
}
.button:disabled {
    cursor: not-allowed;
    opacity: .55;
}
@media (max-width: 980px) {
    .grid-two,
    .results-layout { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .mesai-app { padding: 30px 14px 54px; }
    .mesai-topbar { align-items: stretch; }
    .settings-panel {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: calc(100vh - 28px);
        border-radius: 8px 8px 0 0;
    }
    .workflow { grid-template-columns: 1fr; }
    .panel-heading.spread,
    .calculate-row,
    .bottom-actions { align-items: stretch; flex-direction: column; }
    .range-selector { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .legend { justify-content: flex-start; }
    .summary-grid { grid-template-columns: 1fr; }
    .bottom-actions .button,
    .calculate-row .button { width: 100%; }
    .export-menu,
    .export-menu .button { width: 100%; }
    .button,
    .icon-button,
    .settings-head .icon-button,
    .drawer-head .detail-close,
    .detail-button,
    .segmented button,
    .export-options button,
    select,
    .range-selector input,
    .month-selector input { min-height: 44px; }
    .icon-button,
    .settings-head .icon-button,
    .drawer-head .detail-close,
    .detail-button { min-width: 44px; }
    .switch-row { min-height: 44px; }
    .export-options { right: 0; gap: 4px; }
}
