/* ==================== CSS Variables & Reset ==================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f5f0eb;
    --surface: #ffffff;
    --surface-hover: #faf8f5;
    --text: #2c2420;
    --text-secondary: #8c7a6e;
    --border: #e8e0d8;
    --accent: #b8755c;
    --accent-hover: #a0644d;
    --accent-light: #fdf0ea;
    --danger: #d96060;
    --danger-hover: #c45050;
    --shadow-sm: 0 1px 3px rgba(44, 36, 32, 0.06);
    --shadow-md: 0 4px 16px rgba(44, 36, 32, 0.08);
    --shadow-lg: 0 12px 40px rgba(44, 36, 32, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --transition: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select { font-family: inherit; font-size: inherit; }

/* ==================== Pages ==================== */
.page { height: 100vh; width: 100vw; }
.page.active { display: flex !important; }

/* ==================== Auth Page ==================== */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 24px;
    background: linear-gradient(135deg, #f5f0eb 0%, #ede4da 50%, #f0e8e0 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
}

.auth-header { text-align: center; margin-bottom: 28px; }
.auth-title { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.auth-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 6px; }

.auth-tabs {
    display: flex; gap: 0; background: var(--bg);
    border-radius: var(--radius-sm); padding: 4px; margin-bottom: 24px;
}

.auth-tab {
    flex: 1; padding: 10px 0; font-size: 14px; font-weight: 500;
    color: var(--text-secondary); border-radius: 6px; transition: var(--transition);
}

.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ==================== Form Elements ==================== */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.required { color: var(--danger); }

.form-group input,
.form-group select {
    padding: 10px 14px; border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); font-size: 15px; color: var(--text);
    background: var(--surface); transition: var(--transition); outline: none; width: 100%;
}

.form-group input:focus,
.form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.form-group input::placeholder { color: #c4b8ae; }
.form-group select:disabled { background: #f9f7f4; color: #b0a69c; cursor: not-allowed; }

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

.form-error {
    font-size: 13px; color: var(--danger); background: #fef0f0;
    padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid #fdd;
}

/* Buttons */
.btn-primary {
    width: 100%; padding: 12px 0; background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
    transition: var(--transition); letter-spacing: 0.5px;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-danger {
    padding: 10px 24px; background: var(--danger); color: #fff;
    border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
    transition: var(--transition);
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-cancel {
    padding: 10px 24px; background: var(--bg); color: var(--text-secondary);
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; transition: var(--transition);
}
.btn-cancel:hover { background: var(--border); }

/* ==================== Wardrobe Layout ==================== */
.wardrobe-layout { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
.sidebar {
    width: 280px; min-width: 280px; background: var(--surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden;
}

.sidebar-header { padding: 24px 20px 16px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-title { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }

.btn-all {
    padding: 6px 16px; background: var(--accent-light); color: var(--accent);
    border-radius: 20px; font-size: 13px; font-weight: 600; transition: var(--transition);
}
.btn-all:hover { background: var(--accent); color: #fff; }

.category-tree { flex: 1; overflow-y: auto; padding: 0 12px 16px; }
.tree-loading { padding: 24px 16px; color: var(--text-secondary); font-size: 13px; }

.category-group { margin-bottom: 4px; }
.category-parent {
    font-size: 12px; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 1px; padding: 10px 8px 4px;
}

.category-children { display: flex; flex-direction: column; gap: 2px; }
.category-child {
    display: block; width: 100%; text-align: left; padding: 8px 12px;
    font-size: 14px; color: var(--text); border-radius: var(--radius-sm);
    transition: var(--transition); cursor: pointer;
}
.category-child:hover { background: var(--bg); color: var(--accent); }
.category-child.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }
.btn-logout {
    width: 100%; padding: 8px 0; font-size: 13px; color: var(--text-secondary);
    border: 1.5px solid var(--border); border-radius: var(--radius-sm); transition: var(--transition);
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); background: #fef0f0; }

/* Main Content */
.main-content { flex: 1; overflow-y: auto; padding: 24px 32px; }

.content-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.header-left { display: flex; align-items: baseline; gap: 12px; }
.header-left h3 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.result-count { font-size: 13px; color: var(--text-secondary); }

.btn-add {
    padding: 10px 22px; background: var(--accent); color: #fff;
    border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
    transition: var(--transition); box-shadow: var(--shadow-sm);
}
.btn-add:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-add:active { transform: translateY(0); }

/* Tag Filters */
.tag-filters {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-bottom: 20px; padding: 12px 0;
}
.tag-filter-group { display: flex; align-items: center; gap: 6px; }
.tag-filter-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; white-space: nowrap; }
.tag-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.tag-btn {
    padding: 4px 14px; font-size: 13px; color: var(--text-secondary);
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 20px; transition: var(--transition); cursor: pointer;
}
.tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.tag-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-clear-tags { font-size: 12px; color: var(--danger); padding: 4px 12px; border-radius: 20px; transition: var(--transition); }
.btn-clear-tags:hover { background: #fef0f0; }

/* Clothing Grid */
.clothing-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px;
}
.grid-loading { grid-column: 1 / -1; text-align: center; padding: 48px; color: var(--text-secondary); font-size: 14px; }

/* Clothing Card */
.clothing-card {
    background: var(--surface); border-radius: var(--radius-lg);
    overflow: hidden; box-shadow: var(--shadow-sm); transition: var(--transition); cursor: default;
}
.clothing-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }

.card-image { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: #f0ebe3; }
.card-body { padding: 12px 14px; }
.card-name {
    font-size: 14px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px;
}
.card-brand { font-size: 12px; color: var(--accent); font-weight: 500; margin-bottom: 4px; }
.card-category { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.card-tag { font-size: 11px; padding: 2px 8px; background: var(--accent-light); color: var(--accent); border-radius: 10px; }
.card-actions { display: flex; gap: 8px; }
.card-btn { flex: 1; padding: 6px 0; font-size: 12px; border-radius: 6px; font-weight: 500; transition: var(--transition); text-align: center; }
.card-btn-edit { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }
.card-btn-edit:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.card-btn-delete { background: #fef0f0; color: var(--danger); border: 1px solid #fdd; }
.card-btn-delete:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Empty State */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { color: var(--text-secondary); font-size: 14px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 32px; padding-bottom: 24px; }
.page-btn {
    padding: 8px 20px; font-size: 13px; background: var(--surface); color: var(--text);
    border: 1.5px solid var(--border); border-radius: var(--radius-sm); transition: var(--transition);
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 13px; color: var(--text-secondary); }

/* ==================== Modal ==================== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(44, 36, 32, 0.4);
    backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 24px;
}

.modal {
    width: 100%; max-width: 520px; max-height: 90vh; background: var(--surface);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow-y: auto;
    animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-small { max-width: 400px; }

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: var(--text-secondary); border-radius: 50%; transition: var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }

#form-clothing { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; padding: 0 24px 24px; }

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border); border-radius: var(--radius-md);
    padding: 24px; text-align: center; cursor: pointer; transition: var(--transition);
    min-height: 120px; display: flex; align-items: center; justify-content: center;
}
.upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.upload-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.upload-icon { font-size: 28px; }
.upload-placeholder span:nth-child(2) { font-size: 13px; color: var(--text); font-weight: 500; }
.upload-hint { font-size: 11px; color: var(--text-secondary); }
.upload-preview { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: var(--radius-sm); }

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .wardrobe-layout { flex-direction: column; }
    .sidebar { width: 100%; min-width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
    .main-content { padding: 16px; }
    .clothing-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
    .content-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .btn-add { width: 100%; text-align: center; }
    .modal { max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; margin-top: auto; }
    .form-row { grid-template-columns: 1fr; }
    .auth-card { padding: 28px 24px; border-radius: var(--radius-lg); }
}