@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;600&family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #c8d3df;

  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-light: #3b82f6;
  --brand-dim: #eff6ff;
  --brand-text: #1e40af;

  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f8fafc;
  --sidebar-item-hover: #1e293b;
  --sidebar-accent: #60a5fa;

  --success: #059669;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --info-text: #0c4a6e;

  --font: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-ui: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', 'Monaco', monospace;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --shadow: 0 4px 8px rgba(15,23,42,0.06), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-md: 0 8px 20px rgba(15,23,42,0.08), 0 3px 8px rgba(15,23,42,0.04);
  --shadow-lg: 0 20px 40px rgba(15,23,42,0.12), 0 8px 16px rgba(15,23,42,0.06);

  --transition: 180ms ease;
  --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* === ADMIN LAYOUT === */
.layout-admin {
  display: flex;
  min-height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.04);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-logo {
  padding: 1.5rem 1.25rem 1.125rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo-eyebrow {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--sidebar-accent);
  margin-bottom: 0.35rem;
  font-family: var(--font-ui);
}

.sidebar-logo-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #f1f5f9;
  line-height: 1.4;
}

.sidebar-nav {
  padding: 0.875rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar-section-label {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #334155;
  padding: 0.875rem 0.875rem 0.375rem;
  font-family: var(--font-ui);
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.525rem 0.875rem;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-family: var(--font);
  font-size: 0.845rem;
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: all var(--transition);
  position: relative;
}

.sidebar-btn:hover {
  background: rgba(255,255,255,0.06);
  color: #e2e8f0;
}

.sidebar-btn.active {
  background: rgba(96, 165, 250, 0.14);
  color: #f0f9ff;
  font-weight: 600;
}

.sidebar-btn.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 50%;
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
  border-radius: 0 3px 3px 0;
}

.sidebar-btn svg {
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity var(--transition);
}
.sidebar-btn.active svg,
.sidebar-btn:hover svg { opacity: 1; }

.sidebar-btn.danger { color: #f87171; }
.sidebar-btn.danger:hover {
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
}

.sidebar-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 0.5rem 0.75rem;
}

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

/* === MAIN === */
.admin-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 1rem;
}

.page-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.page-content { padding: 1.75rem; flex: 1; }

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* === STATS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.375rem 1.25rem;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--stat-accent, var(--brand));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  opacity: 0.85;
}

.stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-family: var(--font-ui);
}

.stat-value {
  font-size: 1.875rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
}

.stat-sublabel {
  font-size: 0.775rem;
  color: var(--text-secondary);
  margin-top: 0.35rem;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  user-select: none;
  letter-spacing: 0.005em;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); box-shadow: 0 4px 14px rgba(37,99,235,0.35); transform: translateY(-1px); }

.btn-secondary { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text-primary); border-color: #94a3b8; box-shadow: var(--shadow-xs); }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; box-shadow: 0 4px 14px rgba(5,150,105,0.3); transform: translateY(-1px); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-raised); color: var(--text-primary); }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; border-radius: var(--radius-sm); gap: 0.3rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--radius); }

/* === FORMS === */
.form-group { margin-bottom: 1.1rem; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
  letter-spacing: 0.01em;
}

.form-input {
  width: 100%;
  padding: 0.575rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: #fefeff;
}

.form-input::placeholder { color: var(--text-muted); }

select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

textarea.form-input { resize: vertical; min-height: 80px; }

/* === BADGES === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.4;
  font-family: var(--font-ui);
  letter-spacing: 0.01em;
}

.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-text);  }
.badge-info    { background: var(--info-bg);    color: var(--info-text);    }
.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-blue    { background: #eff6ff; color: #1d4ed8; }

/* === TABLES === */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-family: var(--font-ui);
}

.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-raised); }

/* === TABS === */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  gap: 0.125rem;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 0.75rem 1.125rem;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2.5px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover { color: var(--text-secondary); background: var(--surface-raised); }
.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 700;
  background: rgba(37,99,235,0.04);
}

/* === TOGGLE === */
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.toggle-input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  width: 38px;
  height: 21px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--transition);
  position: relative;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-input:checked + .toggle-track { background: var(--success); }
.toggle-input:checked + .toggle-track::after { transform: translateX(17px); }

/* === PROGRESS === */
.progress {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #34d399);
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

/* === ALERTS === */
.alert {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.875rem;
  align-items: flex-start;
}

.alert-success { background: var(--success-bg); border-color: #a7f3d0; color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: #fde68a; color: var(--warning-text); }
.alert-danger  { background: var(--danger-bg);  border-color: #fecaca; color: var(--danger-text);  }
.alert-info    { background: var(--info-bg);    border-color: #bae6fd; color: var(--info-text);    }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeOverlay 0.2s ease;
}

@keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2rem;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.5) inset;
  animation: slideInModal 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideInModal {
  from { opacity: 0; transform: scale(0.93) translateY(-14px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-sm { max-width: 380px; }
.modal-lg { max-width: 680px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* === LOADING === */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  gap: 0.75rem;
  color: var(--text-muted);
}

/* === EMPTY STATE === */
.empty-state { text-align: center; padding: 3rem 2rem; color: var(--text-muted); }

/* === MATERIAL ITEM === */
.material-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.material-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
  transform: translateX(1px);
}

.material-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.material-icon.pdf  { background: #fef2f2; color: #dc2626; }
.material-icon.url  { background: #eff6ff; color: #2563eb; }
.material-icon.text { background: #fafaf9; color: #57534e; }
.material-icon.csv  { background: #f0fdf4; color: #16a34a; }
.material-icon.img  { background: #fdf4ff; color: #9333ea; }

/* === ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: fadeIn 0.22s ease forwards; }

/* === TOAST === */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: #0f172a;
  color: #f1f5f9;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 360px;
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid rgba(255,255,255,0.08);
}

.toast.removing { animation: toastOut 0.25s ease forwards; }
.toast-success { border-left: 3px solid #10b981; }
.toast-error   { border-left: 3px solid #f87171; }
.toast-info    { border-left: 3px solid var(--sidebar-accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px) scale(0.94); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(24px); }
}

/* === UTILS === */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.72rem; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.hidden { display: none !important; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
