:root {
    --bg-base: #e4ecf8;
    --bg-soft: #f4f8ff;
    --surface: #ffffff;
    --surface-muted: #eef4ff;
    --text: #0f1b32;
    --text-muted: #314968;
    --line: #9fb2cd;
    --line-strong: #768daf;
    --primary: #0049d8;
    --primary-strong: #0038aa;
    --primary-soft: #dfeaff;
    --success: #0f754a;
    --warning: #8e4d00;
    --error: #a9282f;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 4px 14px rgba(16, 39, 75, 0.13);
    --shadow-md: 0 12px 28px rgba(12, 31, 60, 0.18);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    color: var(--text);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    background:
        radial-gradient(1000px 460px at -10% -15%, #d3e2ff 0%, transparent 55%),
        radial-gradient(900px 420px at 108% -6%, #d0e8ff 0%, transparent 55%),
        linear-gradient(180deg, #f9fbff 0%, var(--bg-base) 100%);
}

a {
    color: var(--primary);
}

a:hover {
    color: var(--primary-strong);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 120;
    border-bottom: 2px solid #04142f;
    background: linear-gradient(135deg, #081f44 0%, #0b356f 100%);
}

.topbar-inner {
    width: min(1640px, calc(100vw - 28px));
    margin: 0 auto;
    padding: 12px 4px 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
}

.brand-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand-eyebrow {
    margin: 0;
    font-size: 12px;
    letter-spacing: 0.08em;
    color: #c7d8f7;
    text-transform: uppercase;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.18;
    letter-spacing: 0.01em;
    color: #ffffff;
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid #8caadb;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: #f2f7ff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.18s ease;
}

.nav-link:hover {
    border-color: #ffffff;
    background: #ffffff;
    color: #12386f;
    transform: translateY(-1px);
}

.nav-link.is-active {
    color: #112b53;
    border-color: #ffd952;
    background: linear-gradient(135deg, #ffe582 0%, #ffd952 100%);
    box-shadow: 0 4px 12px rgba(9, 24, 47, 0.25);
}

.embedded-topbar {
    display: flex;
    align-items: center;
    min-height: 54px;
    padding: 0 18px;
    border-bottom: 1px solid #14386d;
    background: linear-gradient(135deg, #0e2a57 0%, #123f79 100%);
}

.embedded-topbar h1 {
    margin: 0;
    font-size: 16px;
    color: #ffffff;
}

.app-main {
    width: min(1640px, calc(100vw - 28px));
    margin: 16px auto 28px;
}

.app-main.embedded-main {
    width: min(1640px, calc(100vw - 18px));
    margin-top: 10px;
    margin-bottom: 12px;
}

.card {
    margin-bottom: 16px;
    padding: 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    animation: card-enter 0.24s ease both;
}

@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h2 {
    margin: 0;
    padding-bottom: 9px;
    border-bottom: 1px solid #c7d4e7;
    font-size: 18px;
    letter-spacing: 0.01em;
    color: #112a52;
}

.card > p,
.card > .hint,
.card > .inline-form,
.card > .grid-form,
.card > table,
.card > .pagination-footer {
    margin-top: 12px;
}

.hint {
    margin-bottom: 0;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
}

.flash-stack {
    margin-bottom: 14px;
}

.flash {
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
}

.flash-success {
    color: var(--success);
    border-color: #84c7aa;
    background: #dcf6e9;
}

.flash-warning {
    color: var(--warning);
    border-color: #e0bc73;
    background: #ffefcc;
}

.flash-error {
    color: var(--error);
    border-color: #e6a0a0;
    background: #ffe4e4;
}

.inline-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.grid-form {
    display: grid;
    gap: 10px;
    align-items: end;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid-form .wide {
    grid-column: 1 / -1;
}

label {
    font-size: 13px;
    color: #213f69;
}

input,
select,
textarea,
button {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid #94a9c7;
    font-size: 14px;
    color: var(--text);
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #2a67e6;
    outline: 2px solid rgba(0, 73, 216, 0.2);
    outline-offset: 0;
}

input::placeholder,
textarea::placeholder {
    color: #9aa9bf;
}

textarea {
    resize: vertical;
}

input[type="file"] {
    padding: 6px;
    background: #f8fbff;
}

button {
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
    background: linear-gradient(135deg, #0050ea 0%, #003cac 100%);
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(0, 73, 216, 0.3);
}

button:active {
    transform: translateY(0);
    box-shadow: none;
}

button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #8fa6c5;
    border-radius: var(--radius-md);
    background: #fff;
    overflow: hidden;
}

th,
td {
    padding: 9px 10px;
    border-bottom: 1px solid #d1ddee;
    border-right: 1px solid #d9e4f3;
    text-align: left;
    vertical-align: top;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
}

th:last-child,
td:last-child {
    border-right: 0;
}

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

th {
    position: sticky;
    top: 0;
    z-index: 1;
    color: #16345f;
    font-weight: 700;
    background: linear-gradient(180deg, #e7f0ff 0%, #dbe8fb 100%);
}

tbody tr:nth-child(2n) {
    background: #f4f8ff;
}

tbody tr:hover {
    background: #e6f0ff;
}

.pagination-footer {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.pagination-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.pagination-links a,
.pagination-links .active-page {
    min-width: 32px;
    padding: 5px 10px;
    text-align: center;
    text-decoration: none;
    border-radius: 999px;
    border: 1px solid #a2b8d7;
    color: #244978;
    background: #fff;
}

.pagination-links a:hover {
    border-color: #6e93ca;
    background: #e2ecff;
}

.pagination-links .active-page {
    color: #fff;
    border-color: var(--primary);
    background: var(--primary);
}

.po-detail-table th,
.po-detail-table td {
    white-space: normal;
    word-break: break-word;
}

.po-cn-name-input {
    width: 100%;
    min-width: 280px;
    min-height: 68px;
    line-height: 1.45;
}

.cn-name-cell,
.sku-cell {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.sku-cell {
    align-items: center;
}

.copy-btn,
.info-btn {
    white-space: nowrap;
    color: #173f74;
    border-color: #95add3;
    background: linear-gradient(180deg, #ffffff 0%, #e7efff 100%);
}

.copy-btn:hover,
.info-btn:hover {
    box-shadow: none;
    transform: translateY(-1px);
    border-color: #6e91c8;
    background: #d9e6ff;
}

.info-tooltip {
    position: relative;
    display: inline-block;
}

.info-tooltip-content {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    z-index: 40;
    min-width: 270px;
    max-width: 430px;
    padding: 9px 10px;
    border: 1px solid #a2b7d6;
    border-radius: var(--radius-md);
    background: #fff;
    box-shadow: var(--shadow-md);
    line-height: 1.6;
}

.info-tooltip:hover .info-tooltip-content,
.info-tooltip:focus-within .info-tooltip-content {
    display: block;
}

.arrival-record-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.arrival-record-item {
    white-space: normal;
    word-break: break-word;
}

.po-emphasis-red {
    color: #003ec2;
    font-weight: 700;
}

body.modal-open {
    overflow: hidden;
}

.po-detail-modal {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: none;
}

.po-detail-modal.is-open {
    display: block;
}

.po-detail-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 19, 34, 0.66);
    backdrop-filter: blur(1px);
}

.po-detail-modal-panel {
    position: relative;
    width: min(1500px, 97vw);
    height: 94vh;
    margin: 3vh auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 14px;
    border: 1px solid #6c86aa;
    background: #fff;
    box-shadow: 0 22px 46px rgba(9, 25, 50, 0.44);
}

.po-detail-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #9db3d1;
    background: linear-gradient(180deg, #e7f0ff 0%, #dbe8fb 100%);
}

.po-detail-modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: #173760;
}

.po-detail-close-btn {
    min-width: 72px;
}

#po-detail-modal-frame {
    width: 100%;
    flex: 1;
    border: 0;
    background: #fff;
}

@media (max-width: 1024px) {
    .topbar-inner,
    .app-main,
    .app-main.embedded-main {
        width: calc(100vw - 18px);
    }

    .topbar h1 {
        font-size: 21px;
    }

    .main-nav {
        width: 100%;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 768px) {
    .topbar {
        position: sticky;
        top: 0;
    }

    .topbar-inner {
        padding-top: 10px;
        padding-bottom: 12px;
        gap: 10px;
        align-items: stretch;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .brand-eyebrow {
        font-size: 11px;
    }

    .main-nav {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .main-nav::-webkit-scrollbar {
        height: 4px;
    }

    .main-nav::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.45);
        border-radius: 999px;
    }

    .nav-link {
        flex: 0 0 auto;
        scroll-snap-align: start;
        min-height: 34px;
        padding: 0 11px;
        font-size: 12px;
    }

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

    h2 {
        font-size: 16px;
    }

    .embedded-topbar {
        min-height: 48px;
        padding: 0 12px;
    }

    .embedded-topbar h1 {
        font-size: 15px;
    }

    .inline-form {
        align-items: stretch;
        gap: 8px;
    }

    .inline-form input:not([type="checkbox"]):not([type="radio"]),
    .inline-form select,
    .inline-form textarea,
    .inline-form button {
        width: 100%;
    }

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

    .pagination-footer {
        align-items: stretch;
    }

    .pagination-links {
        gap: 6px;
    }

    .pagination-links a,
    .pagination-links .active-page {
        padding: 4px 8px;
        min-width: 28px;
    }

    th,
    td {
        padding: 7px 8px;
        font-size: 12px;
    }

    table.mobile-card-table {
        display: block;
        border: 0;
        border-radius: 0;
        background: transparent;
        overflow: visible;
    }

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

    table.mobile-card-table tbody,
    table.mobile-card-table tr,
    table.mobile-card-table td {
        display: block;
        width: 100%;
    }

    table.mobile-card-table tbody tr {
        margin-bottom: 10px;
        padding: 8px 10px;
        border: 1px solid #bdcde4;
        border-radius: 12px;
        background: #ffffff;
        box-shadow: var(--shadow-sm);
    }

    table.mobile-card-table tbody tr:last-child {
        margin-bottom: 0;
    }

    table.mobile-card-table td {
        padding: 7px 0;
        border-right: 0;
        border-bottom: 1px dashed #d7e1f0;
        font-size: 13px;
        line-height: 1.48;
    }

    table.mobile-card-table td:last-child {
        border-bottom: 0;
    }

    table.mobile-card-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 3px;
        color: #3e5d89;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.02em;
    }

    table.mobile-card-table td[colspan]::before {
        content: none;
    }

    .cn-name-cell,
    .sku-cell {
        flex-direction: column;
        align-items: stretch;
    }

    .po-cn-name-input {
        min-width: 220px;
    }

    .po-detail-modal-panel {
        width: 100vw;
        height: 100vh;
        margin: 0;
        border: 0;
        border-radius: 0;
    }
}
