:root {
    --bg: #f3f8fc;
    --panel: #ffffff;
    --line: #d7e5f0;
    --text: #1b2b36;
    --muted: #647887;
    --accent: #1d9bd7;
    --accent-dark: #0b6fa4;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, "Noto Sans KR", sans-serif;
    color: var(--text);
    background: var(--bg);
}

body.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 20px;
}

a {
    color: inherit;
    text-decoration: none;
}

.app {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #12344d;
    color: #eef7fc;
    padding: 24px 16px;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 0 8px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, .14);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--accent);
    font-weight: 700;
}

.brand small {
    display: block;
    margin-top: 3px;
    color: #a9c7d9;
}

nav {
    display: grid;
    gap: 6px;
    margin-top: 22px;
}

nav a {
    padding: 12px 12px;
    border-radius: 8px;
    color: #d8ebf7;
}

nav a.active,
nav a:hover {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

nav a.disabled {
    color: #7e918b;
    cursor: not-allowed;
}

.main {
    padding: 28px;
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: flex-end;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
    color: var(--muted);
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    gap: 10px;
}

.topbar-actions a,
.row-actions a {
    color: var(--accent-dark);
    font-weight: 700;
}

.inline-form {
    display: inline;
    margin: 0;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent-dark);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.danger-link {
    color: var(--danger);
}

.danger-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 11px;
    border: 1px solid #f0b8b2;
    border-radius: 8px;
    background: #fff4f2;
    color: var(--danger);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.danger-action-button:hover {
    border-color: #e58b82;
    background: #ffe7e3;
}

.autofill-guard {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 22px;
}

.page-head h1 {
    margin: 0;
    font-size: 26px;
}

.page-head p {
    margin: 6px 0 0;
    color: var(--muted);
}

.telegram-qr-card {
    display: grid;
    grid-template-columns: 50px auto;
    gap: 8px;
    align-items: center;
    min-width: 162px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--accent-dark);
    font-weight: 800;
    box-shadow: 0 8px 22px rgba(18, 52, 77, .08);
}

.telegram-qr-card img,
.telegram-qr-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    border: 1px solid #dceaf3;
    background: #f7fbfe;
}

.alert-template-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, .7fr);
    gap: 22px;
    align-items: start;
}

.alert-template-editors textarea {
    width: 100%;
    min-height: 170px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.55;
}

.phone-preview {
    width: min(100%, 340px);
    min-height: 410px;
    margin: 0 auto;
    padding: 18px 14px;
    border: 8px solid #17222b;
    border-radius: 28px;
    background: linear-gradient(160deg, #d9effb 0%, #f4f9fc 55%, #dcecf4 100%);
    box-shadow: 0 18px 40px rgba(18, 52, 77, .18);
}

.phone-preview-status,
.phone-notification-head,
.phone-preview-tabs {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.phone-preview-status {
    padding: 0 8px 14px;
    color: #17222b;
    font-size: 12px;
    font-weight: 800;
}

.phone-notification {
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 8px 24px rgba(18, 52, 77, .14);
}

.phone-notification-head {
    margin-bottom: 10px;
    color: #607684;
    font-size: 12px;
}

.phone-notification > strong {
    display: block;
    margin-bottom: 7px;
    color: #17222b;
    font-size: 14px;
}

#notification_preview_body {
    color: #263946;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.phone-preview-tabs {
    justify-content: center;
    margin-top: 16px;
}

.preview-type-button {
    padding: 7px 10px;
    border: 1px solid #b7cfdd;
    border-radius: 6px;
    background: #fff;
    color: #365467;
    cursor: pointer;
}

.preview-type-button.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.telegram-qr-card img {
    display: block;
    object-fit: cover;
}

.telegram-qr-placeholder {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 14px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.card,
.table-wrap,
.form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.card {
    padding: 18px;
}

.card span {
    color: var(--muted);
    font-size: 13px;
}

.card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
    overflow-wrap: anywhere;
}

.card small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.section {
    margin-top: 18px;
}

.table-wrap {
    overflow: auto;
    max-height: 640px;
}

.table-scroll {
    max-height: 560px;
}

.table-scroll-summary {
    max-height: 320px;
}

.table-scroll-large {
    max-height: 640px;
}

.table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.log-table-wrap {
    max-height: 680px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

th {
    background: #eaf5fb;
    color: #334b5c;
    font-size: 13px;
}

tr[data-json] {
    cursor: pointer;
}

tr[data-json]:hover {
    background: #f5fbff;
}

tr.order-alert {
    position: relative;
    box-shadow: inset 4px 0 0 var(--danger), inset 0 1px 0 var(--danger), inset 0 -1px 0 var(--danger);
}

tr.order-alert-blacklist {
    background: #fff7f6;
}

tr.order-alert-interest {
    background: #fff8ed;
    box-shadow: inset 4px 0 0 #d97706, inset 0 1px 0 #d97706, inset 0 -1px 0 #d97706;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge.blacklist,
.badge.priority-urgent {
    background: #fee4e2;
    color: #912018;
}

.badge.interest,
.badge.priority-check {
    background: #ffead5;
    color: #9a3412;
}

.badge.priority-normal {
    background: #e8f3fa;
    color: #0b6fa4;
}

.badge.order-status {
    border: 1px solid transparent;
}

.badge.status-income {
    background: #e0f2fe;
    color: #075985;
}

.badge.status-check {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge.status-cooking {
    background: #fef3c7;
    color: #92400e;
}

.badge.status-delivery,
.badge.status-arrived {
    background: #ede9fe;
    color: #6d28d9;
}

.badge.status-completed,
.badge.status-packaged,
.badge.status-pickup {
    background: #dcfce7;
    color: #166534;
}

.badge.status-cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.badge.status-default {
    background: #f1f5f9;
    color: #475569;
}

.alert-note {
    margin-top: 6px;
    max-width: 320px;
    color: #2b363b;
    line-height: 1.4;
}

.muted {
    color: var(--muted);
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.section-title-row h2 {
    margin: 0;
}

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

.button.disabled {
    opacity: .45;
    pointer-events: none;
}

.input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.button:hover {
    background: var(--accent-dark);
}

.button.secondary {
    background: #e8f3fa;
    color: #223038;
}

.button.full {
    width: 100%;
}

.notice {
    padding: 12px 14px;
    border-radius: 8px;
    background: #e7f5fd;
    border: 1px solid #b7ddf2;
    margin-bottom: 16px;
}

.progress-shell {
    height: 14px;
    background: #dceaf3;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 14px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: var(--accent);
    transition: width .2s ease;
}

.sync-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.sync-status {
    color: var(--muted);
    font-weight: 700;
}

.error {
    background: #fff0ee;
    border-color: #f2b8b1;
    color: var(--danger);
}

.form-panel {
    padding: 18px;
    max-width: 760px;
}

.wide-panel {
    max-width: none;
    width: 100%;
}

.login-panel {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
}

.login-panel h1 {
    margin: 0 0 6px;
}

.login-panel p {
    margin: 0 0 20px;
    color: var(--muted);
}

.form-row {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.pos-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.check-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.json-panel {
    white-space: pre-wrap;
    background: #11191d;
    color: #dce8e4;
    border-radius: 8px;
    padding: 16px;
    min-height: 180px;
    overflow: auto;
}

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sync-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .page-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .alert-template-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .main {
        padding: 18px;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .sync-grid {
        grid-template-columns: 1fr;
    }
}
