/* iCRDesk standalone dashboard — self-hosted CSS
 * Phase 5: Tailwind CDN 과 Google Fonts 의존을 제거한 핸드크래프트 스타일.
 * 시스템 폰트 스택만 사용하며 외부 네트워크 호출이 없다.
 */

:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --card-border: #e5e7eb;
  --text: #111827;
  --text-strong: #111827;
  --text-soft: #374151;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: #fff7ed;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --success-deep: #15803d;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --danger-deep: #b91c1c;
  --amber: #f59e0b;
  --info-soft: #eff6ff;
  --info-border: #bfdbfe;
  --info-text: #1d4ed8;
  --border: #e5e7eb;
  --border-soft: #f3f4f6;
  --sidebar-bg: #ffffff;
  --sidebar-width: 240px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.2);
  --radius: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans KR",
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

code {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", monospace;
  font-size: 0.85em;
  background: #dbeafe;
  padding: 1px 6px;
  border-radius: 6px;
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-brand-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
}

.sidebar-brand-subtitle {
  font-size: 10px;
  color: var(--muted-soft);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 8px;
  margin: 20px 0 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-section:first-child {
  margin-top: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover {
  background: var(--border-soft);
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-link--danger {
  color: var(--danger);
}

.sidebar-link--danger:hover {
  background: var(--danger-soft);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-soft);
}

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

.page {
  flex: 1;
  padding: 32px 24px;
}

.page-inner {
  max-width: 1200px;
  margin: 0 auto;
}

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

.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-strong);
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* =====================================================
 * Stat grid + cards
 * ===================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.1;
}

.stat-value--sm {
  font-size: 18px;
}

.stat-value--success {
  color: var(--success);
}

.stat-value--danger {
  color: var(--danger);
}

.stat-value--amber {
  color: var(--amber);
}

/* =====================================================
 * Generic card
 * ===================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
}

.card-body {
  padding: 20px;
}

.card + .card {
  margin-top: 24px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  font-size: 14px;
}

.info-grid dt {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
}

.info-grid dd {
  margin: 0 0 8px;
  font-family: ui-monospace, "SF Mono", monospace;
  color: var(--text-strong);
}

/* =====================================================
 * Tables
 * ===================================================== */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead {
  background: #f9fafb;
}

.table th {
  text-align: left;
  padding: 14px 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.table td {
  padding: 14px 20px;
  font-size: 14px;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
}

.table tbody tr:hover {
  background: #f9fafb;
}

.table-empty {
  text-align: center !important;
  padding: 48px 20px !important;
  color: var(--muted-soft) !important;
  font-size: 14px;
}

.table-mono {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", monospace;
}

.table-actions {
  display: flex;
  gap: 8px;
}

/* =====================================================
 * Badges
 * ===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success-deep);
}
.badge-success .badge-dot {
  background: var(--success);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-deep);
}
.badge-danger .badge-dot {
  background: var(--danger);
}

.badge-muted {
  background: var(--border-soft);
  color: var(--muted);
}
.badge-muted .badge-dot {
  background: var(--muted-soft);
}

/* =====================================================
 * Buttons
 * ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:hover {
  background: #f9fafb;
}

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-link {
  background: transparent;
  border: 0;
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px 16px;
}

/* =====================================================
 * Forms
 * ===================================================== */
.form {
  max-width: 520px;
}

.form-field {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.form-required {
  color: var(--danger);
  margin-left: 2px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: var(--text-strong);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}

.form-input[readonly] {
  background: #f9fafb;
  color: var(--muted);
}

.form-sep {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 8px 0 16px;
}

/* =====================================================
 * Alerts
 * ===================================================== */
.alert {
  padding: 16px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert-title {
  font-weight: 600;
  margin: 0 0 8px;
}

.alert-list {
  margin: 0;
  padding-left: 18px;
}

.alert-info {
  background: var(--info-soft);
  border: 1px solid var(--info-border);
  color: var(--info-text);
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger-deep);
}

.alert-success {
  background: var(--success-soft);
  border: 1px solid #bbf7d0;
  color: var(--success-deep);
}

/* =====================================================
 * Utility
 * ===================================================== */
.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", monospace;
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-placeholder,
.error-placeholder {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted-soft);
  font-size: 14px;
}

.error-placeholder p {
  color: var(--danger);
  margin: 0 0 8px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =====================================================
 * Auth (login) page
 * ===================================================== */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(251, 146, 60, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.08), transparent 24%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  padding: 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

.auth-brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

.auth-brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-footer {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
