* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #f5f7fb;
    color: #111827;
}

a { color: inherit; }

.admin-container {
    max-width: 1220px;
    margin: 0 auto;
    padding: 0 20px;
}

.admin-topbar {
    background: #111827;
    color: #ffffff;
    border-bottom: 1px solid #1f2937;
}

.admin-topbar-inner {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    padding-top: 12px;
    padding-bottom: 12px;
}

.admin-brand {
    color: #ffffff;
    text-decoration: none;
    font-size: 22px;
    font-weight: 700;
}

.admin-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-nav a,
.subnav a {
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
}

.admin-nav a:hover,
.subnav a:hover,
.subnav a.active {
    background: rgba(255,255,255,0.12);
}

.admin-user-area {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.admin-main {
    padding: 28px 0 48px;
}

.admin-footer {
    border-top: 1px solid #dbe3ee;
    background: #ffffff;
    color: #6b7280;
    padding: 18px 0;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.page-head h1,
.card h2 {
    margin: 0;
}

.card {
    background: #ffffff;
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 8px 24px rgba(17,24,39,0.04);
}

.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    background: #ffffff;
    border: 1px solid #dbe3ee;
    border-radius: 12px;
    padding: 18px;
}

.stat-card h2 {
    margin: 0 0 6px;
    font-size: 14px;
    color: #6b7280;
}

.stat-number {
    font-size: 30px;
    font-weight: 700;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-form {
    display: inline;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    background: transparent;
}

.btn-primary {
    background: #2563eb;
    color: #ffffff;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-outline {
    border-color: #9ca3af;
    color: #111827;
    background: #ffffff;
}
.btn-outline:hover { background: #f3f4f6; }

.btn-danger {
    background: #dc2626;
    color: #ffffff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-warning {
    background: #f59e0b;
    color: #ffffff;
}
.btn-warning:hover { background: #d97706; }

.search-row form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    background: #ffffff;
}

.search-row input[type="text"] { min-width: 300px; }
.search-row select { min-width: 180px; }

textarea {
    min-height: 140px;
    resize: vertical;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.form-group { margin-bottom: 16px; }
.form-group.full { grid-column: 1 / -1; }
.field-help { margin: 6px 0 0; color: #6b7280; font-size: 13px; }
.muted { color: #6b7280; }

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}

th {
    font-size: 13px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: #e5e7eb;
    color: #111827;
    text-transform: capitalize;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-muted { background: #e5e7eb; color: #374151; }

.alert {
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid;
}
.alert-success {
    background: #ecfdf5;
    color: #166534;
    border-color: #86efac;
}
.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fca5a5;
}

.detail-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 10px 16px;
}
.detail-label {
    color: #6b7280;
    font-weight: 700;
}

.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.thread-stack {
    display: grid;
    gap: 16px;
}

.thread-message {
    background: #ffffff;
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    padding: 18px;
}
.thread-message-admin {
    border-width: 2px;
    border-color: #bfdbfe;
    background: #f8fbff;
}
.thread-message-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.thread-message-body {
    white-space: pre-wrap;
    line-height: 1.55;
}

@media (max-width: 860px) {
    .form-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .search-row input[type="text"],
    .search-row select {
        min-width: 0;
        width: 100%;
    }
}


.btn-icon {
    min-width: 36px;
    padding: 8px 10px;
}

.category-tree-table .is-hidden {
    display: none;
}

.category-tree-name {
    display: flex;
    align-items: center;
    gap: 6px;
}

.category-tree-name.depth-1 { padding-left: 18px; }
.category-tree-name.depth-2 { padding-left: 36px; }
.category-tree-name.depth-3 { padding-left: 54px; }
.category-tree-name.depth-4 { padding-left: 72px; }
.category-tree-name.depth-5 { padding-left: 90px; }

.tree-toggle,
.tree-name-button {
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0;
    color: inherit;
    font: inherit;
}

.tree-toggle {
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.tree-toggle-spacer {
    display: inline-block;
    width: 18px;
}

.tree-name-button {
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.tree-name-text {
    font-weight: 600;
}

.child-count {
    color: #6b7280;
    font-weight: 600;
}

.category-path {
    margin-top: 4px;
    font-size: 13px;
}

.order-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.order-number {
    min-width: 24px;
    font-weight: 700;
}

.order-buttons {
    display: inline-flex;
    gap: 6px;
}

.checkbox-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 600;
}

.check-row input[type="checkbox"] {
    width: auto;
}


.category-tree-row.is-hidden {
    display: none;
}

.category-tree-name {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: calc(var(--depth, 0) * 20px);
}

.tree-toggle,
.tree-name-button {
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0;
    color: inherit;
    font: inherit;
}

.tree-toggle {
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 18px;
}

.tree-toggle-spacer {
    display: inline-block;
    width: 18px;
    flex: 0 0 18px;
}

.tree-name-button {
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.tree-name-text {
    font-weight: 600;
}

.child-count {
    color: #6b7280;
    font-weight: 600;
}

.category-path {
    margin-top: 4px;
    font-size: 13px;
}

.order-number {
    min-width: 24px;
    font-weight: 700;
}

.category-tree-row.is-last-child td {
    padding-bottom: 20px;
}


/* ===== Category tree connectors ===== */
.category-tree-table {
    table-layout: fixed;
}

.category-tree-table th:nth-child(1),
.category-tree-table td:nth-child(1) { width: 84px; }
.category-tree-table th:nth-child(3),
.category-tree-table td:nth-child(3) { width: 110px; }
.category-tree-table th:nth-child(4),
.category-tree-table td:nth-child(4) { width: 140px; }
.category-tree-table th:nth-child(5),
.category-tree-table td:nth-child(5) { width: 120px; }

.category-tree-row td {
    padding-top: 10px;
    padding-bottom: 10px;
}

.category-tree-row.is-hidden {
    display: none;
}

.category-tree-name {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding-left: 0 !important;
}

.tree-connectors {
    display: inline-flex;
    align-items: stretch;
    flex: 0 0 auto;
    height: 32px;
}

.tree-connector {
    position: relative;
    width: 20px;
    height: 32px;
    flex: 0 0 20px;
}

.tree-connector.vertical::before,
.tree-connector.tee::before,
.tree-connector.elbow::before {
    content: "";
    position: absolute;
    left: 8px;
    width: 2px;
    background: #111111;
}

.tree-connector.vertical::before,
.tree-connector.tee::before {
    top: -14px;
    bottom: -14px;
}

.tree-connector.elbow::before {
    top: -14px;
    height: 30px;
}

.tree-connector.tee::after,
.tree-connector.elbow::after {
    content: "";
    position: absolute;
    top: 15px;
    left: 8px;
    width: 12px;
    height: 2px;
    background: #111111;
}

.tree-toggle,
.tree-toggle-spacer {
    width: 16px;
    min-width: 16px;
    height: 16px;
    flex: 0 0 16px;
}

.tree-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.tree-toggle-icon {
    display: block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 0;
    position: relative;
}

.tree-toggle[data-state="closed"] .tree-toggle-icon::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid #111111;
}

.tree-toggle[data-state="open"] .tree-toggle-icon::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 10px;
    height: 10px;
    background: #111111;
    border-radius: 999px;
}

.tree-name-button,
.tree-name-text {
    font-size: 16px;
    line-height: 1.3;
}

.tree-name-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.child-count {
    color: #6b7280;
    font-weight: 700;
}

.category-tree-row.has-open-children > td:nth-child(2) .tree-toggle::after {
    content: "";
    position: absolute;
    left: 7px;
    top: 13px;
    width: 2px;
    height: 19px;
    background: #111111;
}

@media (max-width: 860px) {
    .category-tree-table th:nth-child(1),
    .category-tree-table td:nth-child(1),
    .category-tree-table th:nth-child(3),
    .category-tree-table td:nth-child(3) {
        width: auto;
    }
}


/* ===== Category attribute editor ===== */
.category-attributes-panel {
    margin-top: 10px;
    border-top: 1px solid #e5e7eb;
    padding-top: 22px;
}

.category-attributes-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.category-attributes-head h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.attribute-editor-row {
    border: 1px solid #dbe3ee;
    border-radius: 14px;
    background: #f8fbff;
    padding: 18px;
    margin-bottom: 16px;
}

.attribute-editor-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px 16px;
}

.attribute-editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
    padding-top: 8px;
}

.checkbox-stack-inline {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 14px;
}

.attribute-editor-row textarea {
    min-height: 120px;
}

@media (max-width: 980px) {
    .attribute-editor-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .attribute-editor-grid {
        grid-template-columns: 1fr;
    }

    .attribute-editor-footer {
        align-items: flex-start;
        flex-direction: column;
    }
}


.tiny-meta-col {
    width: 58px;
    text-align: center;
}

.variation-meta-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 3px 6px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.variation-meta-empty {
    color: #9ca3af;
    font-weight: 700;
}
