:root {
    --bg: #f5efe6;
    --panel: rgba(255, 250, 242, 0.9);
    --panel-strong: #fff8ef;
    --text: #2f241f;
    --muted: #6f5d54;
    --line: rgba(78, 53, 39, 0.12);
    --brand: #bf5b35;
    --brand-dark: #8a3a1c;
    --accent: #254f4a;
    --shadow: 0 18px 40px rgba(73, 42, 23, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Yu Gothic UI", "Hiragino Sans", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(191, 91, 53, 0.16), transparent 24%),
        radial-gradient(circle at left center, rgba(37, 79, 74, 0.12), transparent 22%),
        linear-gradient(180deg, #f8f1e7 0%, #f3ebdf 100%);
}

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

.sidebar {
    padding: 28px 22px;
    border-right: 1px solid var(--line);
    background: rgba(255, 248, 239, 0.72);
    position: sticky;
    top: 0;
    height: 100vh;
    transition: padding 0.2s ease;
}

.sidebar-toggle {
    margin-left: auto;
    margin-bottom: 18px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-grid;
    place-items: center;
}

.toggle-closed {
    display: none;
}

.logo-block {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 14px;
    align-items: center;
    margin-bottom: 26px;
}

.logo-mark {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    display: block;
    object-fit: contain;
    background: var(--panel-strong);
    padding: 4px;
    box-shadow: var(--shadow);
}

.logo-title {
    margin: 4px 0 0;
    font-size: 1.5rem;
}

.sidebar-user {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.menu-list {
    display: grid;
    gap: 10px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.menu-item:hover {
    transform: translateX(2px);
    background: rgba(255, 255, 255, 0.7);
}

.menu-item.active {
    background: rgba(255, 255, 255, 0.92);
    border-color: var(--line);
    box-shadow: var(--shadow);
}

.menu-icon {
    width: 22px;
    min-width: 22px;
    display: inline-grid;
    place-items: center;
    font-size: 1rem;
    line-height: 1;
}

.menu-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.menu-label {
    display: inline-block;
}

:root.sidebar-collapsed .app-shell {
    grid-template-columns: 96px minmax(0, 1fr);
}

:root.sidebar-collapsed .sidebar {
    padding: 28px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

:root.sidebar-collapsed .logo-block {
    grid-template-columns: 1fr;
    justify-items: center;
    width: 100%;
}

:root.sidebar-collapsed .logo-block > div:not(.logo-mark) {
    display: none;
}

:root.sidebar-collapsed .sidebar-toggle {
    display: grid;
    margin-left: auto;
    margin-right: auto;
}

:root.sidebar-collapsed .menu-list {
    width: 100%;
    justify-items: center;
}

:root.sidebar-collapsed .menu-item {
    justify-content: center;
    width: 68px;
    min-height: 52px;
    padding-left: 0;
    padding-right: 0;
}

:root.sidebar-collapsed .menu-label {
    display: none;
}

:root.sidebar-collapsed .menu-icon {
    width: auto;
    min-width: 0;
    font-size: 1.2rem;
}

:root.sidebar-collapsed .toggle-open {
    display: none;
}

:root.sidebar-collapsed .toggle-closed {
    display: inline;
}

.content-pane {
    min-width: 0;
}

.page {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.page-wide {
    width: calc(100% - 64px);
    max-width: 1680px;
}

.hero {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 24px;
    align-items: start;
    margin-bottom: 24px;
}

.hero-single {
    grid-template-columns: 1fr;
}

.eyebrow {
    margin: 0 0 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--brand-dark);
    font-size: 0.75rem;
    font-weight: 700;
}

h1, h2, h3, strong {
    font-family: Georgia, "Times New Roman", serif;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 1.05;
}

.lead {
    max-width: 56rem;
    color: var(--muted);
    font-size: 1.02rem;
}

.stat-grid,
.panel-grid {
    display: grid;
    gap: 16px;
}

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

.stat-card,
.panel,
.company-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.stat-card {
    padding: 20px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    margin-bottom: 8px;
}

.stat-card strong {
    font-size: 2rem;
}

.period-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.period-tab {
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
}

.period-tab.active {
    background: var(--accent);
    color: #fff;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.metric-card {
    min-height: 230px;
    padding: 28px;
    display: grid;
    grid-template-columns: 1fr 0.9fr;
    gap: 18px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.metric-label {
    margin: 0 0 20px;
    font-weight: 800;
    font-size: 1.05rem;
}

.metric-value {
    display: block;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    line-height: 1;
    margin-bottom: 14px;
}

.metric-note {
    color: var(--muted);
    font-weight: 700;
}

.metric-art {
    position: relative;
    min-height: 130px;
}

.mail-art::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 44px;
    width: 82px;
    height: 58px;
    border: 2px solid var(--text);
    transform: rotate(-12deg) skewX(-8deg);
    background: linear-gradient(135deg, transparent 48%, var(--text) 49%, var(--text) 51%, transparent 52%);
}

.mail-art span {
    position: absolute;
    display: block;
    border: 1.8px solid #2d76ff;
}

.mail-art span:nth-child(1) {
    width: 32px;
    height: 32px;
    right: 54px;
    top: 18px;
}

.mail-art span:nth-child(2) {
    width: 42px;
    height: 42px;
    right: 18px;
    top: 66px;
}

.mail-art span:nth-child(3) {
    width: 62px;
    right: 84px;
    top: 76px;
}

.mail-art span:nth-child(4) {
    width: 78px;
    right: 30px;
    bottom: 18px;
}

.open-art::before {
    content: "";
    position: absolute;
    left: 20px;
    top: 34px;
    width: 120px;
    height: 78px;
    border: 2px solid var(--text);
    clip-path: polygon(0 0, 50% 48%, 100% 0, 100% 100%, 0 100%);
}

.open-art::after {
    content: "";
    position: absolute;
    right: 12px;
    top: 30px;
    width: 88px;
    height: 72px;
    border: 2px solid #2d76ff;
    clip-path: polygon(0 48%, 100% 0, 78% 50%, 100% 100%);
}

.click-art::before {
    content: "";
    position: absolute;
    left: 24px;
    top: 16px;
    width: 76px;
    height: 76px;
    border: 2px solid #2d76ff;
    border-right-color: transparent;
    border-bottom-color: transparent;
    border-radius: 50%;
}

.click-art::after {
    content: "";
    position: absolute;
    left: 64px;
    top: 42px;
    width: 78px;
    height: 92px;
    border: 2px solid var(--text);
    border-radius: 18px 28px 24px 18px;
    transform: rotate(-45deg);
}

.dashboard-help {
    max-width: 100%;
}

.panel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 24px;
}

.panel,
.company-card {
    padding: 22px;
}

.stack {
    display: grid;
    gap: 14px;
}

.schedule-cancel-form {
    margin-top: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}

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

input,
textarea,
select {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
}

button {
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    background: var(--brand);
    color: white;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
    background: var(--brand-dark);
}

button:disabled {
    background: #b9b3ac;
    color: #f7f2ec;
    cursor: not-allowed;
    transform: none;
}

button:disabled:hover {
    background: #b9b3ac;
}

button.secondary {
    background: var(--accent);
}

.hint,
.company-notes,
.empty {
    color: var(--muted);
}

.subtext {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.92rem;
    word-break: break-all;
}

.flash {
    margin-bottom: 18px;
    padding: 14px 18px;
    border-radius: 16px;
    border: 1px solid var(--line);
}

.flash-success {
    background: #d8ebe0;
}

.flash-error {
    background: #f1dfd7;
}

.auth-shell {
    min-height: 100vh;
    padding: 32px;
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(560px, 100%);
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.auth-title {
    margin: 0 0 14px;
    font-size: clamp(2rem, 4vw, 3rem);
}

.auth-lead {
    margin: 0 0 24px;
    color: var(--muted);
    line-height: 1.7;
}

.settings-panel {
    max-width: 720px;
}

.settings-page .settings-panel {
    max-width: none;
}

.settings-table th {
    width: 220px;
}

.settings-user-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}

.settings-user-table th,
.settings-user-table td {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
}

.settings-user-table th {
    width: auto;
}

.settings-user-table th:last-child,
.settings-user-table td:last-child {
    width: 380px;
    overflow-wrap: normal;
}

.settings-col-user-id {
    width: 6%;
}

.settings-col-username {
    width: 7%;
}

.settings-col-email {
    width: 11%;
}

.settings-col-company-id {
    width: 6%;
}

.settings-col-company-name {
    width: 10%;
}

.settings-col-role {
    width: 5%;
}

.settings-col-from {
    width: 10%;
}

.settings-col-config {
    width: 9%;
}

.settings-col-limit {
    width: 8%;
}

.settings-col-ai {
    width: 7%;
}

.settings-col-actions {
    width: 380px;
}

.limit-cell {
    color: var(--ink);
    font-weight: 800;
    white-space: nowrap;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
}

.delete-progress {
    display: grid;
    gap: 10px;
}

.delete-progress-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.delete-progress-status {
    color: var(--muted);
    font-weight: 700;
}

.delete-progress-bar {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(47, 36, 31, 0.12);
}

.delete-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
    transition: width 0.25s ease;
}

.delete-progress-text {
    margin: 0;
    color: var(--muted);
}

.delete-progress-eta {
    margin: 0;
    color: var(--brand-dark);
    font-size: 0.94rem;
    font-weight: 700;
}

.company-list {
    display: grid;
    gap: 18px;
}

.company-header {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    align-items: start;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.action-stack {
    display: grid;
    gap: 10px;
    min-width: 180px;
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.campaign-header-actions {
    align-items: flex-start;
}

.campaign-header-actions .inline-form button {
    min-height: 50px;
}

.split-send-control {
    display: inline-flex;
    align-items: stretch;
    position: relative;
    gap: 0;
}

.split-send-control .inline-form {
    margin: 0;
}

.split-primary-form {
    margin: 0;
}

.split-primary-form .split-primary-button {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    margin-right: 0;
    min-height: 50px;
    padding: 14px 24px;
}

.split-send-menu {
    position: relative;
    display: inline-flex;
}

.split-send-menu summary {
    list-style: none;
}

.split-send-menu summary::-webkit-details-marker {
    display: none;
}

.split-toggle-button {
    width: 56px;
    min-width: 56px;
    height: 100%;
    min-height: 50px;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.22);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 999px;
    border-bottom-right-radius: 999px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: -1px;
}

.split-toggle-button::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 7px solid #fff;
}

.split-send-menu[open] .split-toggle-button {
    background: var(--brand-dark);
}

.schedule-popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(360px, calc(100vw - 80px));
    padding: 18px;
    border-radius: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    z-index: 10;
}

.schedule-popover h3 {
    margin: 0 0 14px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.pagination {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.pagination-meta {
    min-width: 96px;
    text-align: center;
    color: var(--muted);
    font-weight: 700;
}

.pagination-link {
    min-width: 84px;
}

.template-grid {
    grid-template-columns: 0.8fr 1.2fr;
}

.control-group + .control-group {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.control-group form + form {
    margin-top: 12px;
}

.html-editor-panel {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.58);
    overflow: hidden;
}

.html-preview-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
}

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

.preview-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-weight: 600;
}

.preview-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.preview-switch-label {
    font-size: 0.92rem;
}

.preview-switch-track {
    width: 58px;
    height: 32px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(37, 79, 74, 0.18);
    display: inline-flex;
    align-items: center;
    transition: background 0.18s ease;
}

.preview-switch-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 4px 10px rgba(37, 79, 74, 0.18);
    transition: transform 0.18s ease, background 0.18s ease;
}

.preview-switch input:checked + .preview-switch-track {
    background: rgba(191, 91, 53, 0.22);
}

.preview-switch input:checked + .preview-switch-track .preview-switch-thumb {
    transform: translateX(26px);
    background: var(--brand);
}

.preview-surface {
    display: none;
}

.preview-surface.is-active {
    display: block;
}

.html-editor-panel textarea {
    border: 0;
    border-radius: 0;
    min-height: 360px;
    background: rgba(255, 255, 255, 0.35);
}

.preview-frame {
    width: 100%;
    min-height: 360px;
    border: 0;
    background: #fff;
}

.template-preview-grid {
    display: grid;
    grid-template-columns: 0.8fr 1.1fr 1.1fr;
    gap: 16px;
}

.template-preview-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.56);
    min-width: 0;
}

.template-preview-card h3 {
    margin: 0 0 12px;
    font-size: 1rem;
}

.template-preview-card p {
    margin: 0;
}

.template-preview-card pre {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: inherit;
    line-height: 1.65;
}

.template-preview-frame {
    width: 100%;
    min-height: 220px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.send-form {
    margin-top: 12px;
}

.hidden-field {
    display: none;
}

.result-summary {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--panel-strong);
}

.result-summary.success {
    background: #d8ebe0;
}

.result-summary.manual,
.result-summary.failed {
    background: #f1dfd7;
}

.confirm-panel {
    padding: 18px;
    border-radius: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    text-decoration: none;
}

.company-header h2 {
    margin: 0 0 6px;
}

.company-card section {
    margin-top: 18px;
}

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

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.breakable {
    word-break: break-all;
}

.inline-form {
    display: inline-block;
    margin: 0 4px 4px 0;
}

.inline-form button {
    padding: 8px 12px;
    font-size: 0.92rem;
}

.compact-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.compact-form input {
    padding: 8px 10px;
    font-size: 0.86rem;
}

.compact-form select {
    width: auto;
    min-width: 180px;
    flex: 0 0 auto;
}

.compact-form input[name="monthly_send_limit"] {
    border-color: rgba(28, 77, 68, 0.35);
    font-weight: 800;
}

.compact-switch {
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid rgba(51, 43, 39, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
}

.settings-user-table th,
.settings-user-table td {
    vertical-align: top;
}

.status {
    display: inline-block;
    padding: 4px 10px;
    min-width: 92px;
    border-radius: 999px;
    background: #eadcc8;
    text-align: center;
    white-space: nowrap;
}

.status.approved {
    background: #d8ebe0;
}

.status.manual_followup {
    background: #f1dfd7;
}

.status.sent {
    background: #d6e3f3;
}

.status.suppressed {
    background: #e7e2d6;
}

.log-list {
    list-style: none;
    padding: 0;
    margin: 16px 0 0;
    display: grid;
    gap: 10px;
}

.log-list li {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
}

a {
    color: var(--brand-dark);
}

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

    .sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .hero,
    .panel-grid,
    .template-grid,
    .template-preview-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .company-header {
        flex-direction: column;
    }

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

    .schedule-popover {
        right: auto;
        left: 0;
        width: min(360px, calc(100vw - 64px));
    }
}

@media (max-width: 640px) {
    .page {
        width: min(100% - 20px, 100%);
        padding-top: 20px;
    }

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

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    td {
        padding-left: 0;
        padding-right: 0;
    }
}
