/* ============================================
   ORIX - Compact shadcn/ui Inspired CSS
   데이터 중심 UI를 위한 컴팩트 디자인
   ============================================ */

:root {
  /* Colors - Dark Theme */
  --background: 224 71% 4%;
  --foreground: 213 31% 91%;
  --card: 224 71% 4%;
  --card-foreground: 213 31% 91%;
  --popover: 224 71% 4%;
  --popover-foreground: 213 31% 91%;
  --primary: 210 40% 98%;
  --primary-foreground: 222.2 47.4% 1.2%;
  --secondary: 222.2 47.4% 11.2%;
  --secondary-foreground: 210 40% 98%;
  --muted: 223 47% 11%;
  --muted-foreground: 215.4 16.3% 56.9%;
  --accent: 216 34% 17%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 63% 31%;
  --destructive-foreground: 210 40% 98%;
  --border: 216 34% 17%;
  --input: 216 34% 17%;
  --ring: 213 94% 68%;

  /* Brand */
  --brand: #3b82f6;
  --brand-dark: #2563eb;

  /* Compact spacing */
  --sp-1: 0.125rem;
  --sp-2: 0.25rem;
  --sp-3: 0.5rem;
  --sp-4: 0.75rem;
  --sp-5: 1rem;
  --sp-6: 1.5rem;

  /* Typography - Compact */
  --text-xs: 0.6875rem;
  --text-sm: 0.75rem;
  --text-base: 0.8125rem;
  --text-lg: 0.875rem;
  --text-xl: 1rem;
  --text-2xl: 1.125rem;

  --radius: 0.375rem;
  --radius-sm: 0.25rem;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  font-size: var(--text-base);
  line-height: 1.4;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  min-height: 100vh;
}

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px;
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 50;
}
.main {
  flex: 1;
  margin-left: 200px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Sidebar */
.sidebar-header {
  padding: var(--sp-4);
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.sidebar-logo { color: var(--brand); }
.sidebar-title { font-size: var(--text-sm); font-weight: 600; }
.sidebar-nav { flex: 1; padding: var(--sp-3); overflow-y: auto; }
.nav-section { margin-bottom: var(--sp-4); }
.nav-label {
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-1);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  color: hsl(var(--foreground));
  text-decoration: none;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.nav-item:hover { background: hsl(var(--accent)); }
.nav-item.active { background: var(--brand); color: white; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: var(--sp-3);
  border-top: 1px solid hsl(var(--border));
}
.user-box {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: hsl(var(--accent));
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 28px;
  height: 28px;
  background: var(--brand);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: white;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: var(--text-xs); font-weight: 500; display: block; }
.user-role { font-size: var(--text-xs); color: hsl(var(--muted-foreground)); }
.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
  cursor: pointer;
}
.logout-btn:hover {
  background: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
}

/* Header */
.header {
  height: 40px;
  padding: 0 var(--sp-4);
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.breadcrumb { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-sm); }
.breadcrumb a { color: hsl(var(--muted-foreground)); text-decoration: none; }
.breadcrumb a:hover { color: hsl(var(--foreground)); }
.breadcrumb span { color: hsl(var(--muted-foreground)); }
.header-actions { display: flex; align-items: center; gap: var(--sp-2); }

/* Content */
.content { flex: 1; padding: var(--sp-4); overflow-y: auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-4); }
.page-title { font-size: var(--text-lg); font-weight: 600; }
.page-desc { font-size: var(--text-xs); color: hsl(var(--muted-foreground)); }

/* Cards */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}
.card-header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-title { font-size: var(--text-sm); font-weight: 600; }
.card-body { padding: var(--sp-4); }
.card-body.compact { padding: 0; }

/* Stats Grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.stat {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--sp-3);
}
.stat-label { font-size: var(--text-xs); color: hsl(var(--muted-foreground)); margin-bottom: var(--sp-1); }
.stat-value { font-size: var(--text-xl); font-weight: 700; }
.stat-value.blue { color: #3b82f6; }
.stat-value.green { color: #22c55e; }
.stat-value.yellow { color: #eab308; }
.stat-value.red { color: #ef4444; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}
th {
  font-weight: 500;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--accent));
  position: sticky;
  top: 0;
}
tr:hover { background: hsl(var(--accent) / 0.5); }
td.truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
td.right, th.right { text-align: right; }
td.center, th.center { text-align: center; }
td.mono { font-family: monospace; font-size: var(--text-xs); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}
.btn-secondary:hover { background: hsl(var(--accent)); }

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
}
.btn-ghost:hover { background: hsl(var(--accent)); }

.btn-danger {
  background: hsl(var(--destructive));
  color: white;
}
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: var(--sp-1) var(--sp-2); font-size: 0.625rem; }
.btn-icon { padding: var(--sp-2); }

.btn-group { display: flex; gap: var(--sp-1); }

/* Forms */
.form-group { margin-bottom: var(--sp-3); }
.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  margin-bottom: var(--sp-1);
  color: hsl(var(--foreground));
}
.form-input, .form-select, .form-control {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-sm);
  color: #f1f5f9;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.form-select, select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}
.form-select option, select.form-control option {
  background: #1e293b;
  color: #f1f5f9;
  padding: 8px;
}
.form-input:focus, .form-select:focus, .form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
.form-input::placeholder, .form-control::placeholder { color: #64748b; }
.form-input:disabled, .form-select:disabled, .form-control:disabled {
  background: #0f172a;
  color: #64748b;
  cursor: not-allowed;
}
.form-input.sm, .form-select.sm, .form-control.sm { padding: var(--sp-1) var(--sp-2); font-size: var(--text-xs); }

/* Number input - hide spinners */
input[type="number"].form-control {
  -moz-appearance: textfield;
}
input[type="number"].form-control::-webkit-outer-spin-button,
input[type="number"].form-control::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-row { display: flex; gap: var(--sp-3); }
.form-row > * { flex: 1; }

.form-inline {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-inline .form-group { margin-bottom: 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: 9999px;
  line-height: 1;
}
.badge-default { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-primary { background: #3b82f6; color: white; }
.badge-success { background: #22c55e; color: white; }
.badge-warning { background: #eab308; color: #000; }
.badge-danger { background: #ef4444; color: white; }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: var(--sp-4);
}
.tab {
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: hsl(var(--foreground)); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: var(--sp-1);
  padding: var(--sp-3);
}
.page-link {
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--text-xs);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: hsl(var(--foreground));
}
.page-link:hover { background: hsl(var(--accent)); }
.page-link.active { background: var(--brand); color: white; border-color: var(--brand); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none !important;
  align-items: center;
  justify-content: center;
  z-index: 100;
  visibility: hidden;
  pointer-events: none;
}
.modal-overlay.show { display: flex !important; visibility: visible; pointer-events: auto; }
.modal {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s;
}
.modal-overlay.show .modal { transform: scale(1); }
.modal-header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-title { font-size: var(--text-sm); font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}
.modal-body { padding: var(--sp-4); max-height: 60vh; overflow-y: auto; }
.modal-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid hsl(var(--border));
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* Alert */
.alert {
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-3);
}
.alert-error { background: hsl(var(--destructive) / 0.2); color: #fca5a5; border: 1px solid hsl(var(--destructive)); }
.alert-success { background: rgba(34, 197, 94, 0.2); color: #86efac; border: 1px solid #22c55e; }

/* Toast */
.toast {
  position: fixed;
  bottom: var(--sp-4);
  right: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-size: var(--text-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 3px solid #22c55e; }
.toast.error { border-left: 3px solid #ef4444; }

/* Grid Layouts */
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* Utility */
.text-muted { color: hsl(var(--muted-foreground)); }
.text-sm { font-size: var(--text-xs); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-mono { font-family: monospace; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.hidden { display: none !important; }

/* Link */
.link { color: var(--brand); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Login Page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--sp-6);
}
.login-header { text-align: center; margin-bottom: var(--sp-5); }
.login-logo { color: var(--brand); margin-bottom: var(--sp-3); }
.login-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--sp-1); }
.login-subtitle { font-size: var(--text-xs); color: hsl(var(--muted-foreground)); }

/* Reference Tab Navigation */
.ref-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.ref-tab {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  color: hsl(var(--foreground));
  text-decoration: none;
  transition: all 0.15s;
}
.ref-tab:hover { background: hsl(var(--accent)); }
.ref-tab.active { background: var(--brand); color: white; border-color: var(--brand); }
.ref-tab .count {
  background: rgba(255,255,255,0.2);
  padding: 0 var(--sp-2);
  border-radius: 9999px;
  margin-left: var(--sp-1);
  font-size: 0.625rem;
}

/* Loading */
.loading { position: relative; pointer-events: none; }
.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
}
.loading.active::after { display: flex; align-items: center; justify-content: center; }
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid hsl(var(--border));
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
