:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --surface-2: #fafafa;
    --border: #ebebeb;
    --border-strong: #dcdcdc;
    --text: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #9a9a9a;
    --accent: #1a1a1a;
    --accent-soft: #f0f0ee;
    --accent-hover: #333333;
    --danger: #c0392b;
    --danger-soft: #fdf2f1;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
    --sidebar-w: 220px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --transition: 0.18s ease;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 28px 22px 24px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
    line-height: 1.4;
}

.brand-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    object-fit: contain;
    border-radius: 6px;
}

.brand-copy small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.sidebar-nav {
    padding: 0 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 450;
    transition: background var(--transition), color var(--transition);
}

.nav-icon {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: color var(--transition);
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.nav-label {
    flex: 1;
    min-width: 0;
}

.sidebar-nav a:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.sidebar-nav a:hover .nav-icon {
    color: var(--text-secondary);
}

.sidebar-nav a.active {
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 500;
}

.sidebar-nav a.active .nav-icon {
    color: var(--text);
}

.sidebar-user {
    margin-top: auto;
    padding: 16px 18px 20px;
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto;
    gap: 4px 10px;
    align-items: center;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    grid-row: 1 / span 2;
}

.sidebar-user-meta {
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
    word-break: break-all;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-logout {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
    padding: 7px 12px;
    font-size: 12px;
    margin-top: 4px;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-head {
    padding: 32px 40px 0;
    background: transparent;
    border: none;
}

.page-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}

.content {
    padding: 24px 40px 40px;
    flex: 1;
    max-width: 1440px;
    width: 100%;
}

/* ── Buttons ── */
.btn {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.4;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent-soft);
    border-color: var(--border-strong);
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn.danger {
    background: var(--surface);
    border-color: #e8c4c0;
    color: var(--danger);
}

.btn.danger:hover {
    background: var(--danger-soft);
    border-color: #ddb8b3;
}

.btn.ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn.ghost:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Grid & Panels ── */
.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: 340px 1fr; }
.grid.three { grid-template-columns: 280px minmax(340px, 1fr) 400px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
}

.panel h2 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 18px;
    letter-spacing: -0.01em;
    color: var(--text);
}

.panel h3 {
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 10px;
    color: var(--text-secondary);
}

/* ── Forms ── */
.field { display: block; margin-bottom: 14px; }

.field span {
    display: block;
    font-size: 12.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

input, select {
    width: 100%;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    background: var(--surface);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input:focus, select:focus {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

input::placeholder { color: var(--text-muted); }

.file-picker .file-picker-input {
    width: 100%;
    height: 100%;
    border: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ── Cards ── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border-strong);
}

.card strong {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    margin-top: 10px;
    color: var(--text);
}

.card img {
    width: 100%;
    height: 130px;
    object-fit: contain;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
}

.meta {
    font-size: 12px;
    color: var(--text-muted);
    margin: 5px 0;
    line-height: 1.5;
}

.card .row { margin-top: 12px; }

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.card-title-row strong {
    min-width: 0;
}

.template-list-section + .template-list-section {
    margin-top: 16px;
}

.template-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.template-list-head h2 {
    margin: 0;
}

.template-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.template-badge-public {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent);
}

.template-public-toggle {
    margin-right: auto;
}

/* ── Material Picker Filters ── */
.material-picker-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.material-picker-head h2 {
    margin: 0;
    flex: 1;
}

.material-picker-upload-input {
    display: none;
}

.material-picker-upload-hint {
    margin: 0 0 12px;
}

.material-picker-filters {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

.material-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.material-picker-folder {
    flex: 1 1 140px;
    min-width: 140px;
}

.material-picker-search {
    flex: 1 1 120px;
    min-width: 120px;
}

.material-picker-sort {
    flex: 0 0 auto;
    min-width: 132px;
}

.material-picker-label {
    flex: 0 0 auto;
    font-size: 12px;
    color: var(--text-muted);
    min-width: 28px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}

.filter-chip {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.filter-chip:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.filter-chip.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

/* ── Design Thumbs ── */
.design-thumbs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-height: 48vh;
    overflow: auto;
}

.design-thumb {
    aspect-ratio: 1;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    background: var(--surface-2);
    padding: 0;
    transition: border-color var(--transition);
}

.design-thumb:hover { border-color: var(--border-strong); }

.design-thumb.active {
    border-color: var(--accent);
}

.design-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.material-hover-preview {
    position: fixed;
    display: none;
    z-index: 30;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}

.material-hover-preview.active { display: block; }

.material-panel {
    position: relative;
}

.material-hover-preview-dock {
    width: 380px;
    height: 380px;
    max-width: 380px;
    max-height: 380px;
    overflow: hidden;
    display: none;
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    gap: 8px;
    padding: 16px;
    box-sizing: border-box;
}

.material-hover-preview.material-hover-preview-dock.active {
    display: grid;
}

.material-hover-preview-dock .material-preview-media {
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.material-hover-preview-dock .material-preview-media img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0;
}

.material-hover-preview-dock strong {
    font-size: 14px;
    line-height: 1.4;
    word-break: break-all;
}

.material-hover-preview-dock .meta {
    margin: 0;
}

.material-hover-preview img {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.material-hover-preview strong {
    display: block;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-all;
    margin-bottom: 6px;
}

/* ── Background Strip ── */
.bg-strip {
    display: flex;
    gap: 10px;
    overflow: auto;
    margin-bottom: 14px;
    padding-bottom: 4px;
}

.bg-thumb {
    flex: 0 0 110px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    padding: 6px;
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color var(--transition);
}

.bg-thumb:hover { border-color: var(--border-strong); }
.bg-thumb.active { border-color: var(--accent); }

.bg-thumb img {
    width: 100%;
    height: 76px;
    object-fit: contain;
    background: var(--surface);
    border-radius: 4px;
}

/* ── Custom Checkbox ── */
.ui-check {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.ui-check--inline { flex: 0 0 auto; }

.ui-check input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.ui-check-box {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border-strong);
    border-radius: 5px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.ui-check-box::after {
    content: "";
    width: 5px;
    height: 9px;
    border: 2px solid #fff;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg) scale(0);
    margin-top: -2px;
    transition: transform var(--transition);
}

.ui-check:hover .ui-check-box {
    border-color: var(--text-muted);
    background: var(--accent-soft);
}

.ui-check input:checked + .ui-check-box {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(26, 26, 26, 0.18);
}

.ui-check input:checked + .ui-check-box::after {
    transform: rotate(45deg) scale(1);
}

.ui-check.is-indeterminate .ui-check-box {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(26, 26, 26, 0.18);
}

.ui-check.is-indeterminate .ui-check-box::after {
    width: 8px;
    height: 2px;
    border: 0;
    background: #fff;
    transform: none;
    margin-top: 0;
    border-radius: 1px;
}

.ui-check input:focus-visible + .ui-check-box {
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.ui-check-label {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ── Material List ── */
.material-list-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 10px;
}

.material-list-actions {
    flex: 0 0 auto;
    margin-left: auto;
    gap: 8px;
    align-items: center;
}

.material-list-actions #materialBatchBar {
    gap: 8px;
}

.material-list-toolbar strong {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
}

.material-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.material-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.material-row:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.material-row.selected {
    border-color: var(--accent);
    background: linear-gradient(90deg, rgba(26, 26, 26, 0.03) 0%, var(--surface) 28%);
    box-shadow: 0 0 0 1px rgba(26, 26, 26, 0.06);
}

.material-row-check {
    flex: 0 0 auto;
    margin: 0;
}

.material-row-thumb {
    flex: 0 0 72px;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-2);
}

.material-row-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.material-row-info {
    flex: 1;
    min-width: 0;
    pointer-events: none;
}

.material-row-info strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-row-info .meta {
    margin: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-row-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.material-row-actions .btn {
    flex: 0 0 auto;
    padding: 7px 14px;
    font-size: 12.5px;
}

/* ── Output List ── */
.output-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.output-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.output-row:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.output-row.selected {
    border-color: var(--accent);
    background: linear-gradient(90deg, rgba(26, 26, 26, 0.03) 0%, var(--surface) 28%);
    box-shadow: 0 0 0 1px rgba(26, 26, 26, 0.06);
}

.output-row-check {
    flex: 0 0 auto;
    margin: 0;
}

.output-row-thumbs {
    flex: 0 0 168px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.output-thumb,
.output-more {
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}

.output-thumb:hover,
.output-more:hover {
    box-shadow: 0 0 0 2px var(--accent);
    transform: translateY(-1px);
}

.output-row-thumbs img {
    width: 100%;
    height: 52px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--surface-2);
    display: block;
}

.output-row-info {
    flex: 1;
    min-width: 0;
    pointer-events: none;
}

.output-row-info strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.output-row-info .meta {
    margin: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.output-row-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.output-row-actions .btn {
    flex: 0 0 auto;
    padding: 7px 14px;
    font-size: 12.5px;
}

.output-more {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    height: 52px;
    width: 100%;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.gallery-item .gallery-thumb {
    display: block;
    width: 100%;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: zoom-in;
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: box-shadow var(--transition);
}

.gallery-item .gallery-thumb:hover {
    box-shadow: 0 0 0 2px var(--accent);
}

.gallery-item img {
    width: 100%;
    max-height: 68vh;
    object-fit: contain;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    display: block;
}

/* ── Image Viewer ── */
.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.image-viewer.active { display: flex; }

.image-viewer-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    cursor: zoom-out;
}

.image-viewer-shell {
    position: relative;
    z-index: 1;
    width: min(1120px, 96vw);
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    gap: 12px;
    align-items: center;
}

.image-viewer-main {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.image-viewer-main img {
    display: block;
    width: 100%;
    max-height: 78vh;
    object-fit: contain;
    background: var(--surface-2);
}

.image-viewer-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.image-viewer-foot .hint {
    margin: 0;
    text-align: right;
    word-break: break-all;
}

.image-viewer-nav {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), border-color var(--transition), opacity var(--transition);
}

.image-viewer-nav:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
    border-color: rgba(255, 255, 255, 0.45);
}

.image-viewer-nav:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.image-viewer-close {
    position: absolute;
    top: -48px;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
}

/* ── Stage & Crop ── */
.stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    user-select: none;
    touch-action: none;
}

.stage img {
    display: block;
    max-width: 100%;
    height: auto;
    pointer-events: none;
}

.slot-svg { position: absolute; left: 0; top: 0; overflow: visible; }
.slot-poly { fill: rgba(192, 57, 43, 0.12); stroke: var(--danger); stroke-width: 2; pointer-events: auto; cursor: pointer; }
.slot-poly.draft { fill: rgba(26, 26, 26, 0.08); stroke: var(--accent); cursor: crosshair; }
.slot-poly.selected { fill: rgba(26, 26, 26, 0.16); stroke: var(--accent); stroke-width: 3; }
.slot-label { fill: #fff; font-size: 12px; paint-order: stroke; stroke: var(--danger); stroke-width: 4; pointer-events: auto; cursor: pointer; }
.corner { fill: #fff; stroke: var(--accent); stroke-width: 2; cursor: move; pointer-events: auto; }

.crop-wrap {
    position: relative;
    display: block;
    max-width: 100%;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 12px;
    user-select: none;
    touch-action: none;
}

.crop-viewport {
    position: relative;
    width: 100%;
    min-height: 320px;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: repeating-conic-gradient(#e8e8e8 0% 25%, #f5f5f5 0% 50%) 50% / 16px 16px;
}

.crop-img {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    cursor: move;
    pointer-events: auto;
    z-index: 1;
}

.crop-frame {
    position: absolute;
    border: 2px solid var(--accent);
    background: transparent;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 2;
}

.crop-frame:after {
    content: "";
    position: absolute;
    inset: 8%;
    border: 1px dashed rgba(192, 57, 43, 0.6);
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: pointer;
    z-index: 3;
    transform: translate(-50%, -50%);
    pointer-events: auto;
}

.crop-handle.tl, .crop-handle.br { cursor: nwse-resize; }
.crop-handle.tr, .crop-handle.bl { cursor: nesw-resize; }

.crop-toolbar {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Preview ── */
.preview-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 72vh;
    overflow: auto;
}

.preview {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    background: var(--surface);
}

.preview canvas {
    width: 100%;
    height: auto;
    background: var(--surface-2);
    border-radius: 4px;
}

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10;
}

.modal.active { display: flex; }

.modal-body {
    width: min(1280px, 96vw);
    max-height: 94vh;
    overflow: auto;
    background: var(--surface);
    border-radius: calc(var(--radius) + 2px);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.modal-body--sm {
    width: min(520px, 96vw);
}

.toolbar {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.toolbar strong {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.checks { display: flex; gap: 12px; flex-wrap: wrap; }

.checks label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

.checks input {
    width: auto;
    height: auto;
    accent-color: var(--accent);
}

.empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: 13px;
}

/* ── Material Pager ── */
.material-pager {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.material-pager .btn {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 12px;
}

.material-pager .hint {
    margin: 0;
    text-align: center;
    flex: 1;
}

.list-pager {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.list-pager-size,
.list-pager-nav,
.list-pager-jump {
    display: flex;
    align-items: center;
    gap: 8px;
}

.list-pager-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.list-pager-select,
.list-pager-input {
    min-width: 72px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
}

.list-pager-input {
    width: 72px;
}

.list-pager-info {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.list-pager .btn {
    padding: 6px 12px;
    font-size: 12px;
}

@media (max-width: 900px) {
    .list-pager {
        flex-direction: column;
        align-items: stretch;
    }
    .list-pager-nav {
        justify-content: center;
        flex-wrap: wrap;
    }
    .list-pager-jump {
        justify-content: center;
    }
}

/* ── File Picker ── */
.file-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 72px;
    padding: 14px 16px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.file-picker:hover {
    border-color: var(--text-muted);
    background: var(--accent-soft);
}

.file-picker.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.file-picker.has-files {
    border-style: solid;
    border-color: var(--border-strong);
    background: var(--surface);
}

.file-picker-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.file-picker-icon {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.file-picker-icon svg { width: 18px; height: 18px; display: block; }

.file-picker-body { flex: 1; min-width: 0; }

.file-picker-title {
    display: block;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
}

.file-picker-desc {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.file-picker-name {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-picker-action {
    flex: 0 0 auto;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 12.5px;
    font-weight: 500;
    pointer-events: none;
}

.file-picker.has-files .file-picker-action { background: var(--accent-hover); }

.upload-form { display: flex; flex-direction: column; gap: 14px; }

/* ── Folder Tree ── */
.folder-tree {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    padding: 6px 0;
    max-height: 320px;
    overflow: auto;
}

.folder-tree.compact { max-height: 240px; }

.folder-tree-node { user-select: none; }

.folder-tree-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px 6px 0;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin: 0 6px;
    transition: background var(--transition);
}

.folder-tree-row:hover { background: var(--accent-soft); }

.folder-tree-row.active {
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 500;
}

.folder-tree-toggle {
    width: 22px;
    height: 22px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    flex: 0 0 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    padding: 0;
}

.folder-tree-toggle:hover { background: var(--border); }
.folder-tree-toggle.placeholder { visibility: hidden; pointer-events: none; }

.folder-tree-icon {
    flex: 0 0 16px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-tree-icon svg { width: 14px; height: 14px; display: block; }

.folder-tree-label {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-tree-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition);
}

.folder-tree-row:hover .folder-tree-actions { opacity: 1; }

.folder-tree-btn {
    border: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color var(--transition), color var(--transition);
}

.folder-tree-btn:hover { border-color: var(--text-muted); color: var(--text); }
.folder-tree-btn.danger:hover { border-color: #ddb8b3; color: var(--danger); }

.folder-tree-children {
    display: none;
    padding-left: 14px;
    border-left: 1px solid var(--border);
    margin-left: 16px;
}

.folder-tree-node.open > .folder-tree-children { display: block; }

.folder-tree-select { position: relative; }

.folder-tree-trigger {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    font-size: 13.5px;
    transition: border-color var(--transition);
}

.folder-tree-trigger:hover { border-color: var(--border-strong); }

.folder-tree-trigger-text {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-tree-trigger-text.placeholder { color: var(--text-muted); }

.folder-tree-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 6px 0;
    display: none;
    max-height: 280px;
    overflow: auto;
}

.folder-tree-select.open .folder-tree-dropdown { display: block; }

.folder-filter-panel { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }

.folder-filter-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.folder-filter-head strong { font-size: 13px; font-weight: 600; }

.folder-parent-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 8px 0 0;
    line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 980px) {
    .app { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-brand { padding: 16px 20px 12px; }
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0 12px 12px;
    }
    .page-head { padding: 20px 20px 0; }
    .content { padding: 16px 20px 28px; }
    .grid.two, .grid.three { grid-template-columns: 1fr; }
    .material-row,
    .output-row {
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .material-row-thumb {
        flex: 0 0 64px;
        width: 64px;
        height: 64px;
    }
    .output-row-thumbs {
        flex: 1 1 100%;
        order: 3;
        max-width: none;
    }
    .output-row-actions {
        margin-left: auto;
    }
    .image-viewer-shell {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .image-viewer-nav.prev,
    .image-viewer-nav.next {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        z-index: 2;
    }
    .image-viewer-nav.prev { left: 8px; }
    .image-viewer-nav.next { right: 8px; }
    .image-viewer-close {
        top: 12px;
        right: 12px;
    }
}

/* ── Auth Pages ── */
.auth-page {
    min-height: 100vh;
    background: var(--bg);
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-brand {
    position: absolute;
    top: 24px;
    left: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.auth-subtitle {
    margin: 0 0 20px;
}

.auth-form {
    display: grid;
    gap: 2px;
}

.auth-submit {
    width: 100%;
    margin-top: 8px;
}

.auth-switch {
    margin: 18px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ── Admin Center ── */
.admin-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-tab {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.admin-tab:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.admin-tab.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}

.admin-section {
    display: none;
    margin-top: 16px;
}

.admin-section.active {
    display: block;
}

.admin-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.admin-section-head strong {
    font-size: 15px;
    font-weight: 600;
}

.admin-inline-form input {
    flex: 1 1 140px;
    min-width: 120px;
}

.admin-table-wrap {
    overflow: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.admin-table th {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    background: var(--surface-2);
}

.admin-table tbody tr:hover {
    background: var(--surface-2);
}

.admin-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    display: block;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    background: var(--surface-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.role-badge-super {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    display: block;
}

.admin-remark-input {
    width: 100%;
    min-width: 140px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    font-size: 12px;
    background: var(--surface);
}

/* ── App Dialog ── */
.app-dialog {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
}

.app-dialog.active {
    display: flex;
}

.app-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.app-dialog-card {
    position: relative;
    width: min(400px, 92vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-lg);
    padding: 22px 22px 18px;
    animation: app-dialog-in 0.18s ease;
}

@keyframes app-dialog-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.app-dialog-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.app-dialog-body {
    margin-top: 10px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

.app-dialog-message {
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.app-dialog-input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
}

.app-dialog-input:focus {
    outline: none;
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.app-dialog-actions .btn {
    min-width: 72px;
}

.settings-grid .panel h2 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
}

.settings-desc {
    margin: 0 0 18px;
}

.settings-form {
    max-width: 420px;
}

.settings-form--api {
    max-width: 420px;
}

.settings-api-field {
    margin-bottom: 0;
}

.settings-key-box {
    display: flex;
    align-items: center;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    overflow: hidden;
}

.settings-key-box input {
    flex: 1;
    min-width: 0;
    width: auto;
    height: 38px;
    padding: 0 12px;
    line-height: 38px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    cursor: default;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: none;
}

.settings-key-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    height: 38px;
    border-left: 1px solid var(--border);
}

.settings-key-actions .btn {
    height: 38px;
    padding: 0 14px;
    border: none;
    border-radius: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.settings-key-actions .btn + .btn {
    border-left: 1px solid var(--border);
}

.settings-key-actions .btn:hover {
    background: var(--surface);
}

.settings-key-box input:focus {
    outline: none;
    border-color: transparent;
    box-shadow: none;
}

.settings-actions {
    justify-content: flex-end;
    margin-top: 6px;
}
