@font-face {
    font-family: 'Grift';
    src: url('../fonts/Grift-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Grift';
    src: url('../fonts/Grift-Medium.otf') format('opentype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Grift';
    src: url('../fonts/Grift-SemiBold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Grift';
    src: url('../fonts/Grift-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Grift';
    src: url('../fonts/Grift-Italic.otf') format('opentype');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

:root {
    --bg: #fafaf7;
    --bg-alt: #f3f1ec;
    --text: #1d1d18;
    --text-secondary: #7a7a72;
    --text-muted: #a5a49a;
    --border: #e3e1da;
    --dark: #1c1c16;
    --accent: #f7f4ee;
    --sidebar-bg: #1a1a16;
    --sidebar-text: #bfbfb5;
    --sidebar-hover: #24241e;
    --sidebar-active: #30302a;
    --border-soft: rgba(0,0,0,0.05);
    --font: 'Grift', 'Helvetica Neue', Arial, sans-serif;
    --max-width: 1440px;
    --radius: 0px;
    --nav-height: 64px;
    --sidebar-width: 260px;
    --success: #4d7a4d;
    --warning: #c98c2e;
    --danger: #b04a4a;
    --info: #3a6ea5;
    --card-bg: var(--bg);
    --text-inverse: #fafaf7;
    --badge-success-bg: #edf3e8;
    --badge-success-text: #3d6b3d;
    --badge-warning-bg: #f6f0e2;
    --badge-warning-text: #9a6a28;
    --badge-info-bg: #e8eef4;
    --badge-info-text: #356696;
    --badge-danger-bg: #f2eaea;
    --badge-danger-text: #944040;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    background: var(--bg-alt);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
img { max-width: 100%; display: block; }

/* ===== LAYOUT ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--nav-height);
}

.sidebar-logo img {
    height: 26px;
    filter: brightness(0) invert(1);
}

.sidebar-logo span {
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
}

/* Sidebar Scroll */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* Sidebar Back Arrow */
.sidebar-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: 12px 16px 4px;
    color: rgba(255,255,255,.45);
    border: 1px solid rgba(255,255,255,.08);
    text-decoration: none;
    transition: all .2s;
}
.sidebar-back:hover {
    color: #fff;
    border-color: rgba(255,255,255,.2);
    background: rgba(255,255,255,.05);
}
.sidebar-back i { width: 16px; height: 16px; }

/* Sidebar Nav */
.sidebar-nav {
    padding: 4px 0;
}

.sidebar-label {
    padding: 12px 20px 6px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #7c7c74;
}

/* Sidebar Items */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px 9px 22px;
    font-size: 0.82rem;
    color: var(--sidebar-text);
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    text-decoration: none;
}

.sidebar-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-item.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-item .lucide {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: .7;
}
.sidebar-item.active .lucide {
    opacity: 1;
}

/* Sidebar Spaces (Fixed Bottom) */
.sidebar-spaces {
    border-top: 1px solid rgba(255,255,255,.06);
    padding: 8px 0;
}
.sidebar-spaces-label {
    padding: 6px 20px 4px;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,.25);
    font-weight: 500;
}
.sidebar-space-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px 9px 20px;
    font-size: 0.8rem;
    color: rgba(255,255,255,.35);
    text-decoration: none;
    transition: all .15s;
}
.sidebar-space-item:hover {
    color: rgba(255,255,255,.7);
    background: rgba(255,255,255,.03);
}
.sidebar-space-item.active {
    color: #fff;
    background: rgba(255,255,255,.06);
}
.sidebar-space-item .lucide {
    width: 14px;
    height: 14px;
    opacity: .5;
}
.sidebar-space-item.active .lucide {
    opacity: 1;
}

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #3d3d36;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    color: #fff;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: #9a9a92;
}

/* Main area */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Topbar */
.topbar {
    height: var(--nav-height);
    background: var(--bg);
    border-bottom: 1px solid var(--border-soft);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text);
}

.menu-toggle .lucide {
    width: 22px;
    height: 22px;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border-soft);
    background: var(--bg);
    min-width: 280px;
}

.topbar-search .lucide {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.topbar-search input {
    border: none;
    background: none;
    outline: none;
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--text);
    width: 100%;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-icon {
    position: relative;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    display: flex;
}

.topbar-icon:hover { color: var(--text); }

.topbar-icon .lucide {
    width: 20px;
    height: 20px;
}

.topbar-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--dark);
    color: #fff;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Page content */
.page-content {
    flex: 1;
    padding: 32px 32px 60px;
    max-width: 1440px;
}

.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.page-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

/* ===== COMPONENTS ===== */

/* Cards */
.card {
    background: var(--bg);
    border: 1px solid var(--border-soft);
    padding: 24px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

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

.card-title {
    font-size: 1rem;
    font-weight: 500;
}

.card-value {
    font-size: 2rem;
    font-weight: 500;
    line-height: 1.2;
}

.card-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid var(--border-soft);
    padding: 20px 24px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stat-card-header .lucide {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.stat-card-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.stat-card-value {
    font-size: 1.8rem;
    font-weight: 500;
    line-height: 1.2;
}

.stat-card-change {
    font-size: 0.78rem;
    margin-top: 6px;
}

.stat-card-change.up { color: var(--success); }
.stat-card-change.down { color: var(--danger); }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* Table */
.table-wrap {
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--border-soft);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

th {
    text-align: left;
    padding: 14px 20px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border-soft);
}

td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text);
}

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

tr:hover td { background: rgba(0,0,0,0.015); }

/* Status badges */
.badge {
    display: inline-flex;
    padding: 3px 10px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: none;
    font-weight: 500;
}

.badge-success { color: var(--badge-success-text); background: var(--badge-success-bg); }
.badge-warning { color: var(--badge-warning-text); background: var(--badge-warning-bg); }
.badge-info { color: var(--badge-info-text); background: var(--badge-info-bg); }
.badge-danger { color: var(--badge-danger-text); background: var(--badge-danger-bg); }
.badge-neutral { color: var(--text-secondary); background: var(--bg-alt); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 1px solid var(--dark);
    background: var(--dark);
    color: #fff;
    font-family: var(--font);
    transition: background 0.25s, color 0.25s, border-color 0.25s, transform 0.25s, box-shadow 0.25s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent);
    color: var(--dark);
    border-color: var(--border);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.btn-outline {
    background: transparent;
    color: var(--dark);
}

.btn-outline:hover {
    background: var(--dark);
    color: #fff;
    border-color: var(--dark);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

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

.btn-ghost:hover {
    background: var(--bg-alt);
    color: var(--text);
    border-color: var(--border);
    transform: none;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.72rem;
}

.btn .lucide {
    width: 16px;
    height: 16px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Form elements */
.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-soft);
    font-family: var(--font);
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.25s, box-shadow 0.25s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.03);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Filters */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group select,
.filter-group input {
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    font-family: var(--font);
    font-size: 0.82rem;
    background: var(--bg);
    color: var(--text);
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--border);
}

/* Product grid (catalog) */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.catalog-card {
    background: var(--bg);
    border: 1px solid var(--border-soft);
    cursor: pointer;
    transition: box-shadow 0.3s, border-color 0.3s;
}

.catalog-card:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.04);
    border-color: var(--border);
}

.catalog-card-img {
    width: 100%;
    aspect-ratio: 4/5;
    background: var(--bg-alt);
}

.catalog-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.catalog-card-body {
    padding: 16px;
}

.catalog-card-ref {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.catalog-card-name {
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.catalog-card-category {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.catalog-card-price {
    font-size: 0.95rem;
    font-weight: 500;
    margin-top: 8px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 24px;
}

.tab {
    padding: 12px 20px;
    font-size: 0.85rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    transition: color 0.2s, border-color 0.2s;
    background: none;
    font-family: var(--font);
}

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

.tab.active {
    color: var(--text);
    border-bottom-color: var(--text);
}

/* Notification dropdown */
.notif-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 340px;
    background: var(--bg);
    border: 1px solid var(--border-soft);
    box-shadow: 0 12px 32px rgba(0,0,0,0.04);
    display: none;
    z-index: 300;
    margin-top: 8px;
}

.notif-dropdown.open { display: block; }

.notif-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notif-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s;
}

.notif-item:hover { background: var(--bg-alt); }

.notif-item:last-child { border-bottom: none; }

.notif-item-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.notif-item-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 24px;
}

.pagination a {
    padding: 8px 14px;
    border: 1px solid var(--border-soft);
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.pagination a:hover,
.pagination a.active {
    background: var(--dark);
    color: #fff;
    border-color: var(--dark);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--bg);
}

.login-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.login-left-inner {
    max-width: 400px;
    width: 100%;
}

.login-logo {
    margin-bottom: 40px;
}

.login-logo img {
    height: 32px;
}

.login-title {
    font-size: 1.6rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.login-form .btn {
    width: 100%;
    margin-top: 8px;
}

.login-forgot {
    text-align: center;
    margin-top: 16px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.login-forgot a {
    color: var(--text);
    text-decoration: underline;
}

.login-right {
    flex: 1;
    background: var(--dark);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #fff;
}

.login-right-content {
    max-width: 420px;
}

.login-right h2 {
    font-size: 2rem;
    font-weight: 500;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}

.login-right p {
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 24px;
}

.login-testimonial {
    border-left: 2px solid var(--accent);
    padding-left: 20px;
}

.login-testimonial-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-style: italic;
}

.login-testimonial-author {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Detail page */
.detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
}

.detail-gallery {
    position: relative;
}

.detail-main-img {
    width: 100%;
    aspect-ratio: 4/5;
    background: var(--bg-alt);
    margin-bottom: 12px;
}

.detail-main-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-thumbs {
    display: flex;
    gap: 8px;
}

.detail-thumb {
    width: 72px;
    height: 72px;
    border: 1px solid var(--border-soft);
    cursor: pointer;
    transition: border-color 0.2s;
}

.detail-thumb:hover,
.detail-thumb.active {
    border-color: var(--text-secondary);
}

.detail-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-info h1 {
    font-size: 1.8rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.detail-ref {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.detail-price {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.detail-price-note {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.detail-specs {
    margin-bottom: 24px;
}

.detail-spec {
    display: flex;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.88rem;
}

.detail-spec-label {
    width: 140px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.detail-spec-value {
    flex: 1;
    color: var(--text);
}

.detail-description {
    margin-bottom: 24px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.detail-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.detail-actions .btn { flex: 1; }

/* Selections / Favorites grid */
.selection-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.selection-card {
    background: var(--bg);
    border: 1px solid var(--border-soft);
    padding: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.selection-card-title {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.selection-card-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.selection-card-thumbs {
    display: flex;
    gap: 4px;
}

.selection-card-thumbs img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border: 1px solid var(--border-soft);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state .lucide {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 400px;
    margin: 0 auto 20px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .catalog-grid { grid-template-columns: repeat(3, 1fr); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
    :root { --sidebar-width: 0px; }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.2);
        z-index: 190;
        display: none;
    }

    .sidebar-overlay.open { display: block; }

    .main-area { margin-left: 0; }

    .menu-toggle { display: flex; }

    .page-content { padding: 24px 20px 40px; }

    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    :root { --nav-height: 72px; }

    .topbar {
        padding: 0 12px;
    }

    .topbar-search {
        min-width: 0;
        flex: 1;
    }
    .topbar-search input { width: 100px; }

    .stats-grid { grid-template-columns: 1fr; }
    .catalog-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .selection-grid { grid-template-columns: 1fr; }
    .detail-layout { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    .login-right { display: none; }

    .page-header h1 { font-size: 1.3rem; }
}

@media (max-width: 640px) {
    .topbar-search { border: none; background: none; min-width: 0; }
    .topbar-search input { display: none; }
    .topbar-search .lucide { width: 20px; height: 20px; color: var(--text-secondary); }
    .topbar-icon .lucide { width: 18px; height: 18px; }
}

/* Scrollbar */
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #3d3d36; }

/* Mobile enhancements */
@media (max-width: 768px) {
    .hub-nav { grid-template-columns: 1fr 1fr; }
    .hub-card { padding: 20px 12px; }
    .hub-label { font-size: 0.85rem; }
    .hub-desc { font-size: 0.7rem; }
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .tab { white-space: nowrap; flex-shrink: 0; }
    .page-actions { flex-wrap: wrap; }
    .page-actions .btn { flex: 1; min-width: 0; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    .filter-group { width: 100%; }
    .filter-group select,
    .filter-group input { width: 100%; }
    .selection-grid { grid-template-columns: 1fr; }
    .selection-card-thumbs { flex-wrap: wrap; }
    .detail-actions { flex-direction: column; }
    .detail-actions .btn { width: 100%; }
    .notif-dropdown { width: 100vw; right: -16px; border-radius: 0; }
    .stats-grid .stat-card-value { font-size: 1.4rem; }
    .card { padding: 16px; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { font-size: 0.8rem; }
    th, td { padding: 10px 12px; white-space: nowrap; }
    .grid-2 > .card, .grid-3 > .card, .grid-4 > .card { min-width: 0; overflow-x: auto; }
    .card .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 480px) {
    .hub-nav { grid-template-columns: 1fr; }
    .page-content { padding: 16px 12px 32px; }
    .topbar { padding: 0 12px; }
    .topbar-search { min-width: 0; flex: 1; }
    .topbar-search input { width: 60px; }
    .topbar-right { gap: 8px; }
    .page-header h1 { font-size: 1.1rem; }
    .catalog-card-body { padding: 12px; }
    .catalog-card-name { font-size: 0.85rem; }
    .stat-card { padding: 14px 16px; }
    .login-left { padding: 24px 20px; }
    .login-title { font-size: 1.3rem; }
    .sidebar { width: 240px; }
    .detail-thumbs { flex-wrap: wrap; }
    .detail-thumb { width: 56px; height: 56px; }
}

@media (max-width: 400px) {
    .grid-4 { grid-template-columns: 1fr; }
    .catalog-grid { grid-template-columns: 1fr; }
    .topbar-search { min-width: 40px; }
    .topbar-search input { width: 50px; }
}

/* Mobile: stacked card tables (≤640px) */
@media (max-width: 640px) {
    .table-wrap thead { display: none; }
    .table-wrap tbody tr {
        display: block;
        padding: 10px 12px;
        margin-bottom: 8px;
        background: var(--bg);
        border: 1px solid var(--border-soft);
    }
    .table-wrap tbody tr:hover td { background: transparent; }
    .table-wrap tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border: none;
        border-bottom: 1px solid var(--border-soft);
        font-size: 0.78rem;
        white-space: normal;
        gap: 6px;
        word-break: break-word;
    }
    .table-wrap tbody td:last-child { border-bottom: none; }
    .table-wrap tbody td::before {
        content: attr(data-label);
        font-weight: 500;
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        flex-shrink: 0;
        min-width: 60px;
    }
    .table-wrap tbody td .badge {
        flex-shrink: 0;
    }
}

/* Tactile targets for touch devices */
@media (pointer: coarse) {
    .btn, .sidebar-item, .tab, .catalog-card, .hub-card { min-height: 44px; }
    .btn-icon { min-width: 44px; min-height: 44px; }
    .topbar-icon { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
    .pagination a { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .filter-group select, .filter-group input { min-height: 44px; }
    .form-group input, .form-group select, .form-group textarea { min-height: 44px; }
    .detail-thumb { min-width: 44px; min-height: 44px; }
}

/* Touch action optimization & active feedback */
.btn, .sidebar-item, .tab, .catalog-card, .hub-card, .selection-card, .stat-card {
    touch-action: manipulation;
}
.btn:active, .catalog-card:active, .hub-card:active, .selection-card:active, .stat-card:active, .badge:active {
    transform: scale(0.97);
}

/* Body scroll lock when sidebar open */
body.sidebar-open { overflow: hidden; }

/* Catalog aspect-ratio on mobile */
@media (max-width: 640px) {
    .catalog-card-img { aspect-ratio: 3/4; }
}
@media (max-width: 480px) {
    .catalog-card-img { aspect-ratio: 1/1; }
}

/* Search overlay (mobile) */
.search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 500;
    padding: 16px;
    flex-direction: column;
}
.search-overlay.open { display: flex; }
.search-overlay-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.search-overlay-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-soft);
    font-family: var(--font);
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
}
.search-overlay-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
    padding: 8px;
    touch-action: manipulation;
}

/* Bottom mobile nav */
@media (max-width: 640px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg);
        border-top: 1px solid var(--border-soft);
        z-index: 150;
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom);
        justify-content: space-around;
        height: 72px;
    }
    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 12px;
        font-size: 0.6rem;
        color: var(--text-muted);
        text-decoration: none;
        touch-action: manipulation;
        min-width: 0;
        flex: 1;
    }
    .mobile-bottom-nav a.active { color: var(--dark); }
    .mobile-bottom-nav a .lucide { width: 18px; height: 18px; }
    .main-area { padding-bottom: 52px; }
    .page-content { padding-bottom: 72px; }
    .fab { bottom: 64px; }
}
@media (min-width: 641px) {
    .mobile-bottom-nav { display: none; }
}

/* FAB (Floating Action Button) for mobile */
@media (max-width: 640px) {
    .fab {
        position: fixed;
        bottom: 76px;
        right: 16px;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: var(--dark);
        color: #fff;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(0,0,0,.12);
        z-index: 160;
        touch-action: manipulation;
        transition: transform .2s;
    }
    .fab:active { transform: scale(.92); }
    .fab .lucide { width: 22px; height: 22px; }
}
@media (min-width: 641px) {
    .fab { display: none; }
}

/* Mobile: stacked card tables (≤640px) */
@media (max-width: 640px) {
    .table-wrap thead { display: none; }
    .table-wrap tbody tr {
        display: block;
        padding: 12px 14px;
        margin-bottom: 10px;
        background: var(--bg);
        border: 1px solid var(--border-soft);
    }
    .table-wrap tbody tr:hover td { background: transparent; }
    .table-wrap tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid var(--border-soft);
        font-size: 0.82rem;
        white-space: normal;
        gap: 8px;
    }
    .table-wrap tbody td:last-child { border-bottom: none; }
    .table-wrap tbody td::before {
        content: attr(data-label);
        font-weight: 500;
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        flex-shrink: 0;
        min-width: 80px;
    }
    .table-wrap tbody td .badge {
        flex-shrink: 0;
    }
}
