:root {
  --brand-cyan: #29ABE2;
  --brand-cyan-light: #4FC6F0;
  --brand-navy: #262B45;
  --brand-navy-deep: #1B1E33;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #dde3ee;
  --text: #1f2733;
  --muted: #6b7688;
  --primary: var(--brand-cyan);
  --primary-dark: #1C86B4;
  --danger: #c0392b;
  --success: #1e8a4c;
  --radius: 10px;
  --sidebar-width: 232px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.app-shell.app-shell-auth {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 56px;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--brand-navy) 0%, var(--brand-navy-deep) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
  padding: 0 4px;
  min-height: 40px;
}
.sidebar-brand svg { width: 36px; height: 36px; flex-shrink: 0; border-radius: 8px; }
.sidebar-brand .brand-logo-img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 56px;
  object-fit: contain;
}
.sidebar-brand-text {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.15;
  color: #fff;
}

.sidebar-user {
  font-size: 0.78rem;
  color: #9aa4c0;
  margin-bottom: 18px;
  padding: 0 4px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  word-break: break-word;
  line-height: 1.5;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}
.sidebar-nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #c4cbe0;
  text-decoration: none;
  font-size: 0.9rem;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-nav a.active {
  background: linear-gradient(90deg, var(--brand-cyan), var(--brand-cyan-light));
  color: var(--nav-active-text);
  font-weight: 600;
}

.sidebar-logout { margin-top: auto; padding-top: 14px; }
.sidebar-logout button {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
}
.sidebar-logout button:hover { background: rgba(255,255,255,0.18); }

.sidebar-footer {
  font-size: 0.7rem;
  color: #7b84a3;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.1);
  line-height: 1.5;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.auth-brand svg { width: 48px; height: 48px; border-radius: 10px; }
.auth-brand .brand-logo-img {
  width: auto;
  height: auto;
  max-width: 260px;
  max-height: 72px;
  object-fit: contain;
}
.auth-brand-text { font-weight: 700; font-size: 1.35rem; color: var(--brand-navy); }

.auth-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 8px 0 32px;
}

.main-area { flex: 1; min-width: 0; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    gap: 16px;
  }
  .sidebar-brand { margin-bottom: 0; }
  .sidebar-user { display: none; }
  .sidebar-nav { flex-direction: row; flex: 0; }
  .sidebar-logout { margin-top: 0; margin-left: auto; padding-top: 0; }
  .sidebar-footer { display: none; }
}

.container {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 28px;
}

.auth-container {
  max-width: 440px;
  width: 100%;
  margin: 0 auto 24px;
  padding: 0 20px;
}

.form-row { display: flex; gap: 12px; }
.form-col { flex: 1; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

h1 { font-size: 1.4rem; margin-top: 0; }
h2 { font-size: 1.1rem; }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

input[type="text"], input[type="email"], input[type="password"], input[type="file"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

textarea { resize: vertical; }

.input-uppercase { text-transform: uppercase; }

button, .btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

button:hover, .btn:hover { background: var(--primary-dark); }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-secondary:hover { background: #eaf0fd; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #96271c; }

.btn-small { padding: 6px 12px; font-size: 0.82rem; }

form.inline { display: inline; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.flash-error { background: #fdecea; color: var(--danger); border: 1px solid #f3c2bc; }
.flash-success { background: #e8f6ee; color: var(--success); border: 1px solid #b9e3c8; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.muted { color: var(--muted); }
.actions-row { display: flex; gap: 8px; align-items: center; }

.upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 4px;
}
.upload-row input[type="file"] { flex: 1; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-pending { background: #fff3cd; color: #8a6414; }
.badge-active { background: #e8f6ee; color: var(--success); }
.badge-admin { background: #eaf0fd; color: var(--primary-dark); }
.badge-category { background: #e6f7fc; color: #1477a0; margin-bottom: 6px; margin-right: 4px; }
.badge-system { background: #f1ecfb; color: #6b3fb8; margin-bottom: 6px; margin-right: 4px; }

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 20px;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.84rem;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); }
.filter-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

.preview-frame {
  background: #eef1f6;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow: auto;
  text-align: center;
}

.preview-frame img {
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
  max-width: 100%;
}

.raw-xml {
  white-space: pre-wrap;
  word-break: break-all;
  font-family: Consolas, monospace;
  font-size: 0.78rem;
  background: #1f2733;
  color: #d7e0f0;
  padding: 14px;
  border-radius: 8px;
  max-height: 400px;
  overflow: auto;
}

details summary { cursor: pointer; color: var(--primary); margin-bottom: 10px; }

.raw-xml-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

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

@media (max-width: 900px) {
  .file-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .file-grid { grid-template-columns: 1fr; }
}

.file-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.15s;
}
.file-card:hover {
  box-shadow: 0 4px 14px rgba(30, 40, 60, 0.12);
  transform: translateY(-2px);
}

.file-card-thumb {
  aspect-ratio: 4 / 3;
  background: #eef1f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.file-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.file-card-noimg {
  color: var(--muted);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
}

.file-card-body { padding: 12px 14px; }
.file-card-name {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-card-desc {
  font-size: 0.82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}
.file-card-meta { font-size: 0.76rem; color: var(--muted); }

.file-card-admin { position: relative; }
.file-card-admin > a {
  display: block;
  text-decoration: none;
  color: inherit;
}
.file-card-actions {
  display: flex;
  gap: 8px;
  margin: 0 10px 10px;
}
.file-card-actions form { flex: 1; }
.file-card-actions .btn,
.file-card-actions button {
  width: 100%;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr; }
}

.stat-item { display: flex; flex-direction: column; gap: 8px; }
.stat-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}
.stat-label span:first-child { font-weight: 600; color: var(--text); }

.stat-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.3s ease;
}
.stat-bar-fill-warn { background: var(--danger); }

.detail-image {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 16px;
}

.logo-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.logo-preview img { width: auto; height: auto; max-width: 260px; max-height: 72px; object-fit: contain; }
.logo-preview svg { width: 56px; height: 56px; flex-shrink: 0; }

.color-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.color-field:last-of-type { border-bottom: none; }
.color-field label { margin: 0; }
.color-field input[type="color"] {
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
