/* ===== CSS Variables ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.15);
    --radius: 8px;
    --sidebar-width: 240px;
    --app-font-family: 'Segoe UI', 'Inter', 'Helvetica Neue', Arial, sans-serif;
    --app-line-height: 1.5;
    --app-letter-spacing: 0;
    --app-word-spacing: normal;
    --control-line-height: 1.4;
    --table-line-height: 1.45;
}

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

html[lang="zh-CN"] {
    --app-font-family: 'Microsoft YaHei', 'PingFang SC', 'Noto Sans SC', 'Hiragino Sans GB', 'Source Han Sans SC', 'Heiti SC', 'WenQuanYi Micro Hei', sans-serif;
    --app-line-height: 1.65;
    --app-letter-spacing: 0.01em;
    --app-word-spacing: 0.02em;
    --control-line-height: 1.55;
    --table-line-height: 1.6;
}

body {
    font-family: var(--app-font-family);
    background: var(--gray-50);
    color: var(--gray-800);
    display: flex;
    min-height: 100vh;
    line-height: var(--app-line-height);
    letter-spacing: var(--app-letter-spacing);
    word-spacing: var(--app-word-spacing);
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; line-height: var(--control-line-height); }

input, select, textarea {
    font-family: inherit;
    font-size: 0.95rem;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    outline: none;
    transition: border 0.2s;
    width: 100%;
    line-height: var(--control-line-height);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--gray-200); line-height: var(--table-line-height); }
th { background: var(--gray-100); font-weight: 600; color: var(--gray-700); }
tr:hover { background: var(--gray-50); }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--gray-900);
    color: white;
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.sidebar .logo {
    padding: 0 20px 30px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar .logo h2 { font-size: 1.5rem; letter-spacing: 0.04em; }
.sidebar .logo small { color: var(--gray-400); font-size: 0.8rem; }
.nav-menu {
    list-style: none;
    padding: 20px 0;
    flex: 1;
}
.nav-menu li a {
    display: block;
    padding: 12px 24px;
    color: var(--gray-300);
    transition: all 0.2s;
    font-size: 0.95rem;
    border-left: 3px solid transparent;
}
.nav-menu li a:hover {
    background: rgba(255,255,255,0.05);
    color: white;
}
.nav-menu li a.active {
    background: rgba(37, 99, 235, 0.2);
    color: white;
    border-left-color: var(--primary);
}
.user-info {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.user-info span { font-size: 0.9rem; color: var(--gray-300); }
.btn-logout {
    background: var(--danger);
    color: white;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    transition: opacity 0.2s;
}
.btn-logout:hover { opacity: 0.8; }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 24px 32px;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
}
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}
.top-header h1 { font-size: 1.8rem; font-weight: 700; }
.header-actions { display: flex; gap: 12px; }

/* ===== Buttons ===== */
.btn-primary {
    background: var(--primary);
    color: white;
    padding: 8px 20px;
    border-radius: var(--radius);
    font-weight: 500;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
    padding: 8px 20px;
    border-radius: var(--radius);
    font-weight: 500;
    transition: background 0.2s;
}
.btn-secondary:hover { background: var(--gray-300); }
.btn-success {
    background: var(--success);
    color: white;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.btn-success:hover { opacity: 0.85; }
.btn-danger {
    background: var(--danger);
    color: white;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.btn-danger:hover { opacity: 0.85; }
.btn-warning {
    background: var(--warning);
    color: white;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.btn-warning:hover { opacity: 0.85; }

/* ===== Cards & Grid ===== */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }

/* ===== Stats ===== */
.stat-card {
    background: white;
    padding: 20px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}
.stat-card .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
}
.stat-card .stat-label {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 4px;
}
.stat-card.green { border-left-color: var(--success); }
.stat-card.yellow { border-left-color: var(--warning); }
.stat-card.red { border-left-color: var(--danger); }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 0.9rem;
    color: var(--gray-700);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-error { color: var(--danger); font-size: 0.8rem; margin-top: 4px; display: block; min-height: 1em; white-space: pre-line; }
.field-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.field-header label { margin-bottom: 0; }
.field-counter { color: var(--gray-500); font-size: 0.8rem; white-space: nowrap; }
.form-hint { color: var(--gray-500); font-size: 0.82rem; margin-top: 6px; }
.form-section-label { font-size: 0.85rem; font-weight: 600; color: var(--gray-500); margin: 16px 0 8px; border-bottom: 1px solid var(--gray-200); padding-bottom: 4px; }

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
    background: white;
    padding: 32px;
    border-radius: var(--radius);
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}
.close-btn {
    position: absolute;
    top: 12px; right: 20px;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--gray-400);
    transition: color 0.2s;
}
.close-btn:hover { color: var(--gray-800); }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }
.badge {
    display: inline-block;
    padding: 2px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-200); color: var(--gray-600); }

/* ===== Items ===== */
.item-secondary-text {
    color: var(--gray-500);
    font-size: 0.82rem;
    margin-top: 4px;
}
.item-remark-cell {
    max-width: 260px;
    white-space: pre-wrap;
    word-break: break-word;
}
.item-drawing-count-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-700);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}
.item-drawings-panel {
    padding: 16px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--gray-50);
}
.item-drawing-upload-row {
    margin: 12px 0 16px;
}
.item-drawing-list {
    display: grid;
    gap: 12px;
}
.item-drawing-card {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
}
.item-drawing-thumb {
    width: 72px;
    height: 72px;
    border-radius: 10px;
    background: var(--gray-100);
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    overflow: hidden;
}
.item-drawing-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.item-drawing-meta strong {
    display: block;
    margin-bottom: 4px;
    word-break: break-word;
}
.item-drawing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}
.item-inline-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-size: 0.78rem;
}
.item-drawing-empty {
    padding: 16px;
    text-align: center;
    color: var(--gray-500);
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius);
    background: white;
}

html[lang="zh-CN"] .sidebar .logo h2,
html[lang="zh-CN"] .top-header h1,
html[lang="zh-CN"] .card-title,
html[lang="zh-CN"] .btn-primary,
html[lang="zh-CN"] .btn-secondary,
html[lang="zh-CN"] .btn-warning,
html[lang="zh-CN"] .btn-danger,
html[lang="zh-CN"] .btn-success,
html[lang="zh-CN"] .badge,
html[lang="zh-CN"] th {
    letter-spacing: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar .logo h2, .sidebar .logo small, .nav-menu li a span, .user-info span { display: none; }
    .nav-menu li a { padding: 12px 16px; text-align: center; }
    .main-content { margin-left: 60px; padding: 16px; width: calc(100% - 60px); }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .item-drawing-card { grid-template-columns: 1fr; }
    .item-drawing-thumb { width: 100%; height: 120px; }
    .item-drawing-actions { justify-content: flex-start; }
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }