/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #080c18;
  --card: rgba(255,255,255,0.04);
  --card-solid: #0e1428;
  --primary: #6366f1;
  --primary-light: rgba(99,102,241,0.1);
  --pri-rgb: 99,102,241;
  --accent: #fbbf24;
  --success: #34d399;
  --danger: #f87171;
  --info: #22d3ee;
  --text: #e4e4ed;
  --sub: rgba(255,255,255,0.35);
  --border: rgba(255,255,255,0.06);
  --sidebar-bg: #060a14;
  --sidebar-hover: rgba(99,102,241,0.08);
  --sidebar-active: rgba(99,102,241,0.15);
  --radius: 12px;
  --shadow: 0 0 1px rgba(255,255,255,0.05);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.3);
  --sidebar-width: 260px;
  --transition: 0.3s ease;
}
html { font-size: 14px; }
body {
  font-family: 'Noto Sans JP', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  background-image: radial-gradient(ellipse at 20% 0%, rgba(var(--pri-rgb),0.06) 0%, transparent 50%), radial-gradient(ellipse at 80% 100%, rgba(34,211,238,0.03) 0%, transparent 50%);
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: center;
}
.sidebar-title { font-family: 'Zen Antique Soft', serif; font-size: 1.5rem; font-weight: 400; letter-spacing: 3px; }
.sidebar-subtitle { font-size: 0.75rem; color: rgba(255,255,255,0.6); margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--sidebar-active);
  color: var(--primary);
  border-left-color: var(--primary);
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex; flex-direction: column; gap: 8px;
}
.btn-data {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: none; padding: 8px 12px; border-radius: 6px;
  cursor: pointer; font-size: 0.8rem; font-family: inherit;
  transition: background var(--transition);
}
.btn-data:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ===== Hamburger ===== */
.hamburger {
  display: none;
  position: fixed; top: 16px; left: 16px;
  z-index: 200;
  background: linear-gradient(135deg, var(--primary), #4f46e5); border: none; border-radius: 12px; box-shadow: 0 0 16px rgba(var(--pri-rgb),0.3);
  width: 44px; height: 44px;
  cursor: pointer;
  flex-direction: column; justify-content: center; align-items: center; gap: 5px;
}
.hamburger span {
  display: block; width: 22px; height: 2px; background: #fff;
  transition: all var(--transition);
}

/* ===== Main Content ===== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ===== Pages ===== */
.page { display: none; }
.page.active { display: block; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.page-date { color: var(--sub); font-size: 0.9rem; }

/* ===== Stats Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 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);
  display: flex; align-items: center; gap: 16px;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--pri-rgb),0.2), transparent);
}
.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--pri-rgb),0.15);
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.green { background: rgba(52,211,153,0.12); color: var(--success); }
.stat-icon.orange { background: rgba(251,191,36,0.12); color: var(--accent); }
.stat-icon.blue { background: rgba(34,211,238,0.12); color: var(--info); }
.stat-icon.red { background: rgba(248,113,113,0.12); color: var(--danger); }
.stat-label { color: var(--sub); font-size: 0.8rem; margin-bottom: 4px; }
.stat-value { font-size: 1.4rem; font-weight: 700; }

/* ===== Charts ===== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.chart-card canvas { width: 100% !important; }

/* ===== Alerts ===== */
.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 16px;
}
.alert-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.alert-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }
.alert-list { max-height: 250px; overflow-y: auto; }
.alert-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.alert-item:last-child { border-bottom: none; }
.alert-empty { color: var(--sub); font-size: 0.85rem; padding: 12px; text-align: center; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}

/* ===== Form Elements ===== */
.input {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  outline: none;
  transition: all var(--transition);
  width: 100%;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(var(--pri-rgb),0.1); }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,122,58,0.1); }
.filter-bar .input { width: auto; min-width: 200px; }
select.input { cursor: pointer; }
select.input option { background: var(--card-solid); color: var(--text); }
textarea.input { resize: vertical; }

/* ===== Buttons ===== */
.btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, var(--primary), #4f46e5); color: #fff; box-shadow: 0 0 16px rgba(var(--pri-rgb),0.2); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(var(--pri-rgb),0.3); }
.btn-secondary { background: rgba(255,255,255,0.04); color: var(--sub); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #d97706; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  background: var(--card-solid);
  color: var(--sub);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(var(--pri-rgb),0.03); }
.data-table .actions { display: flex; gap: 6px; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-予定 { background: rgba(251,191,36,.12); color: var(--accent); }
.badge-納品済 { background: rgba(34,211,238,.12); color: var(--info); }
.badge-請求済 { background: rgba(var(--pri-rgb),.12); color: var(--primary); }
.badge-入金済 { background: rgba(52,211,153,.12); color: var(--success); }
.badge-対応中 { background: rgba(251,191,36,.12); color: var(--accent); }
.badge-手配済 { background: rgba(52,211,153,.12); color: var(--success); }
.badge-対応不可 { background: rgba(248,113,113,.12); color: var(--danger); }
.badge-高 { background: rgba(248,113,113,.12); color: var(--danger); }
.badge-中 { background: rgba(251,191,36,.12); color: var(--accent); }
.badge-低 { background: rgba(var(--pri-rgb),.12); color: var(--primary); }

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(6,6,10,0.8);
  backdrop-filter: blur(6px);
  z-index: 300;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.5);
  animation: modalIn 0.25s ease;
}
.modal-lg { max-width: 720px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--sub); line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 600;
  margin-bottom: 6px; color: var(--text);
}
.required { color: var(--danger); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== Delivery Items ===== */
.delivery-items, .estimate-items { margin-bottom: 12px; }
.delivery-item-row, .estimate-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 80px 1fr 80px 60px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.delivery-item-row .input, .estimate-item-row .input {
  font-size: 0.82rem; padding: 8px 10px;
}
.item-amount {
  font-weight: 600; text-align: right; font-size: 0.85rem;
  white-space: nowrap;
}
.delivery-totals {
  margin-top: 16px;
  border-top: 2px solid var(--border);
  padding-top: 12px;
}
.total-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; font-size: 0.9rem;
}
.total-grand { font-weight: 700; font-size: 1.1rem; color: var(--primary); border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }

/* ===== Documents ===== */
.doc-tabs {
  display: flex; gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.doc-tab {
  background: none; border: none;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--sub);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}
.doc-tab:hover { color: var(--text); }
.doc-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.doc-panel { display: none; }
.doc-panel.active { display: block; }
.doc-form {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  margin-bottom: 20px;
}
.doc-form label {
  font-size: 0.8rem; font-weight: 600; display: block; margin-bottom: 4px;
}
.doc-form .input { width: auto; min-width: 200px; }

/* ===== Document Preview ===== */
.doc-preview {
  background: #fff;
  color: #1a1a1a;
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: var(--shadow);
  max-width: 800px;
}
.doc-preview:empty { display: none; }
.doc-preview .doc-header {
  display: flex; justify-content: space-between; margin-bottom: 32px;
}
.doc-preview .doc-title {
  font-size: 1.6rem; font-weight: 700; color: var(--primary);
  border-bottom: 3px solid var(--primary);
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.doc-preview .company-info { font-size: 0.82rem; line-height: 1.8; }
.doc-preview .client-info { font-size: 0.82rem; line-height: 1.8; text-align: right; }
.doc-preview .client-name { font-size: 1.1rem; font-weight: 700; }
.doc-preview table {
  width: 100%; border-collapse: collapse; margin: 20px 0;
}
.doc-preview table th {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  font-size: 0.82rem;
  text-align: left;
}
.doc-preview table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.doc-preview table td.right, .doc-preview table th.right { text-align: right; }
.doc-preview .doc-totals {
  text-align: right; margin: 20px 0;
}
.doc-preview .doc-totals .row {
  display: flex; justify-content: flex-end; gap: 24px;
  padding: 6px 0; font-size: 0.9rem;
}
.doc-preview .doc-totals .row.grand {
  font-size: 1.2rem; font-weight: 700; color: var(--primary);
  border-top: 2px solid var(--primary); padding-top: 12px; margin-top: 8px;
}
.doc-preview .doc-totals .row span:first-child { min-width: 120px; text-align: right; }
.doc-preview .doc-totals .row span:last-child { min-width: 120px; text-align: right; }
.doc-preview .doc-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem; color: var(--sub);
  line-height: 1.8;
}
.doc-preview .doc-number { font-size: 0.85rem; color: var(--sub); margin-bottom: 4px; }
.doc-preview .print-btn-wrap {
  margin-top: 20px;
  text-align: center;
}

/* ===== Report ===== */
.report-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(var(--pri-rgb),0.15); }
  50% { box-shadow: 0 0 20px rgba(var(--pri-rgb),0.3); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes borderGlow {
  0%, 100% { border-color: rgba(var(--pri-rgb),0.1); }
  50% { border-color: rgba(var(--pri-rgb),0.25); }
}

/* Page transition */
.page { animation: fadeInUp 0.4s ease; }
.page-header { animation: fadeInLeft 0.5s ease; }

/* Stats animation */
.stat-card { animation: fadeInUp 0.5s ease backwards; }
.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.08s; }
.stat-card:nth-child(3) { animation-delay: 0.16s; }
.stat-card:nth-child(4) { animation-delay: 0.24s; }
.stat-card:nth-child(5) { animation-delay: 0.32s; }

/* Chart cards animation */
.chart-card { animation: fadeInUp 0.5s ease 0.3s backwards; }

/* Alert cards animation */
.alert-card { animation: fadeInUp 0.5s ease 0.4s backwards; }

/* Table rows */
.data-table tbody tr { animation: fadeInUp 0.3s ease backwards; }
.data-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.data-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.data-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.data-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.data-table tbody tr:nth-child(5) { animation-delay: 0.25s; }
.data-table tbody tr:nth-child(n+6) { animation-delay: 0.3s; }

/* Button hover effects */
.btn { transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.btn-primary:active { transform: scale(0.96); }

/* Nav items */
.nav-item { transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.nav-item:active { transform: scale(0.97); }
.nav-item.active { animation: pulse-glow 3s ease infinite; }

/* Sidebar logo pulse */
.sidebar-logo { animation: float 4s ease infinite; }

/* Interactive card glow */
.stat-card:hover::before { animation: shimmer 1.5s ease; background-size: 200% 100%; }
.chart-card { transition: all 0.3s; }
.chart-card:hover { transform: translateY(-3px); border-color: rgba(var(--pri-rgb),0.2); box-shadow: 0 8px 30px rgba(0,0,0,0.2); }

/* Badge animation */
.badge { transition: all 0.2s; }
.badge:hover { transform: scale(1.05); }

/* Modal animation */
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Sidebar transition */
.sidebar { transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

/* Scroll reveal for sections */
.page > * { animation: fadeInUp 0.4s ease backwards; }

/* DM Stats grid */
#dmStats > * { animation: scaleIn 0.4s ease backwards; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  html { font-size: 13px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 40px rgba(0,0,0,0.5); }
  .hamburger { display: flex; }
  .main-content { margin-left: 0; padding: 16px 12px; padding-top: 68px; }

  /* ページヘッダー */
  .page-header { margin-bottom: 16px; }
  .page-header h2 { font-size: 1.2rem; }

  /* 統計カード */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; border-radius: 10px; }
  .stat-icon svg { width: 20px; height: 20px; }
  .stat-value { font-size: 1.15rem; }
  .stat-label { font-size: 0.72rem; }

  /* グラフ */
  .charts-grid { grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
  .chart-card { padding: 14px; }
  .chart-card h3 { font-size: 0.9rem; margin-bottom: 10px; }

  /* アラート */
  .alerts-grid { grid-template-columns: 1fr; gap: 12px; }
  .alert-card { padding: 14px; }
  .alert-card h3 { font-size: 0.9rem; }

  /* テーブル */
  .data-table th { padding: 10px 8px; font-size: 0.7rem; }
  .data-table td { padding: 10px 8px; font-size: 0.78rem; }
  .data-table .actions { flex-wrap: wrap; }

  /* フィルター */
  .filter-bar { flex-direction: column; gap: 8px; }
  .filter-bar .input { min-width: auto; width: 100%; }

  /* フォーム */
  .form-row { grid-template-columns: 1fr; gap: 12px; }

  /* 納品品目行 */
  .delivery-item-row, .estimate-item-row {
    grid-template-columns: 1fr;
    gap: 6px;
    background: rgba(255,255,255,0.02);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
  }
  .delivery-item-row .input, .estimate-item-row .input {
    font-size: 0.85rem; padding: 10px 12px;
  }
  .item-amount { text-align: left; padding: 4px 0; font-size: 0.9rem; }
  .delivery-item-row .btn-sm, .estimate-item-row .btn-sm { width: 100%; justify-content: center; }

  /* 書類タブ */
  .doc-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc-tab { padding: 10px 14px; font-size: 0.82rem; white-space: nowrap; }

  /* 書類フォーム */
  .doc-form { flex-direction: column; align-items: stretch; gap: 10px; }
  .doc-form .input { width: 100%; min-width: auto; }
  .doc-form label { margin-top: 4px; }

  /* 書類プレビュー */
  .doc-preview { padding: 20px 16px; max-width: 100%; }
  .doc-preview .doc-header { flex-direction: column; gap: 16px; }
  .doc-preview .client-info { text-align: left; }
  .doc-preview .doc-title { font-size: 1.3rem; }
  .doc-preview .client-name { font-size: 1rem; }
  .doc-preview table th { padding: 8px 6px; font-size: 0.72rem; }
  .doc-preview table td { padding: 8px 6px; font-size: 0.78rem; }
  .doc-preview .doc-totals .row { gap: 16px; font-size: 0.82rem; }
  .doc-preview .doc-totals .row.grand { font-size: 1rem; }
  .doc-preview .doc-totals .row span:first-child { min-width: 80px; }
  .doc-preview .doc-totals .row span:last-child { min-width: 80px; }
  .doc-preview .doc-footer { font-size: 0.75rem; }

  /* 手動入力エリア */
  .manual-item-row { flex-direction: column !important; }
  .manual-item-row .input { width: 100% !important; flex: none !important; }
  .manual-item-row .btn { width: 100%; justify-content: center; }

  /* モーダル */
  .modal-overlay { padding: 16px 8px; align-items: flex-start; }
  .modal { border-radius: 12px; }
  .modal-header { padding: 16px; }
  .modal-header h3 { font-size: 1rem; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-lg { max-width: 100%; }

  /* ボタン */
  .btn { padding: 10px 16px; font-size: 0.82rem; }
  .btn-primary, .btn-secondary { width: 100%; justify-content: center; }
  .page-header .btn { width: auto; }

  /* サイドバーオーバーレイ */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(6,10,20,0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
  }
  .sidebar-overlay.active { display: block; }

  /* DM管理 */
  #dmStats { grid-template-columns: repeat(2,1fr) !important; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header > div { width: 100%; flex-wrap: wrap; }
}

/* 小さい画面 (iPhone SE等) */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { flex-direction: row; }
  .main-content { padding: 12px 8px; padding-top: 64px; }
  .page-header h2 { font-size: 1.1rem; }
  #dmStats { grid-template-columns: 1fr !important; }
}

/* ===== Print Styles ===== */
@media print {
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area {
    position: fixed;
    left: 0; top: 0;
    width: 100%;
    height: 100%;
    padding: 15mm;
    background: #fff !important;
    z-index: 99999;
    overflow: visible;
  }
  .sidebar, .hamburger, .main-content { display: none !important; }
  .print-area .print-btn-wrap { display: none !important; }
  .print-area .manual-edit-section { display: none !important; }
  .print-area .doc-header { display: flex; justify-content: space-between; margin-bottom: 20px; }
  .print-area .doc-title { font-size: 24px; font-weight: 700; border-bottom: 3px solid #2d6a4f; padding-bottom: 8px; margin-bottom: 12px; }
  .print-area .doc-number { font-size: 12px; color: #666; margin-bottom: 12px; }
  .print-area .company-info { font-size: 12px; line-height: 1.8; }
  .print-area .client-info { text-align: right; font-size: 13px; line-height: 1.8; }
  .print-area .client-name { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
  .print-area table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 13px; }
  .print-area table th { background: #2d6a4f !important; color: #fff !important; padding: 10px 14px; text-align: left; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-area table td { padding: 8px 14px; border-bottom: 1px solid #ddd; }
  .print-area table .right { text-align: right; }
  .print-area .doc-totals { margin: 20px 0; text-align: right; }
  .print-area .doc-totals .row { display: flex; justify-content: flex-end; gap: 40px; padding: 4px 0; font-size: 14px; }
  .print-area .doc-totals .row span:first-child { color: #666; }
  .print-area .doc-totals .row.grand { font-size: 18px; font-weight: 700; color: #2d6a4f !important; border-top: 2px solid #2d6a4f; padding-top: 8px; margin-top: 8px; }
  .print-area .doc-footer { margin-top: 20px; font-size: 12px; line-height: 1.8; color: #555; }
  .print-area .stamp-area img { width: 70px !important; height: 70px !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 10mm; size: A4; }
}
