/* ==========================================================================
 *  KSK AI Consultant Member Portal - Stylesheet (v8 - レスポンシブ強化版)
 *  PC・タブレット・スマホ全対応
 * ========================================================================== */

:root {
  --clr-primary: #1f7a3c;
  --clr-primary-dark: #145a2b;
  --clr-primary-light: #2fa760;
  --clr-primary-soft: #e6f4ec;
  --clr-primary-tint: #f2faf6;
  --clr-text: #1a202c;
  --clr-text-muted: #4a5568;
  --clr-border: #d8dee5;
  --clr-bg: #f7f9fb;
  --clr-card: #ffffff;
  --clr-danger: #d13a3a;
  --clr-warn: #c97b15;
  --clr-info: #2c6fbf;
  --clr-success: #1f7a3c;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 14px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.18);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  --sidebar-w: 240px;
  --header-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*:before, *:after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font);
  color: var(--clr-text); background: var(--clr-bg); font-size: 14px; line-height: 1.6;
  -webkit-text-size-adjust: 100%; }
img, svg { max-width: 100%; height: auto; vertical-align: middle; }
a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--clr-text); margin-top: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

/* ================================ Layout ================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas: "sidebar header" "sidebar main";
  min-height: 100vh;
}
.app-header {
  grid-area: header;
  background: #fff;
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 8px;
}
.app-header .page-title { font-size: 15px; font-weight: 600; color: var(--clr-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.app-header .header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.app-sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, #134225 0%, #1f7a3c 100%);
  color: #fff;
  padding: 16px 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.app-main { grid-area: main; padding: 20px 24px; overflow-x: auto; min-width: 0; }

/* Brand */
.brand {
  padding: 0 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,.7); }
.sidebar-close {
  display: none;
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 22px; padding: 4px 10px; border-radius: 4px; line-height: 1;
}
.sidebar-close:hover { background: rgba(255,255,255,.1); }

/* Sidebar */
.sidebar-section { padding: 6px 0; }
.sidebar-section-title {
  font-size: 11px;
  color: rgba(255,255,255,.5);
  padding: 8px 18px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.nav a {
  display: flex; align-items: center;
  color: rgba(255,255,255,.88);
  padding: 10px 18px;
  font-size: 13px;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.15); border-left-color: #fff; color: #fff; font-weight: 600; }
.nav a .ic { margin-right: 8px; opacity: .85; display: inline-block; width: 18px; text-align: center; flex-shrink: 0; }

/* オーバーレイ(スマホでサイドバーを開いた時) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 290;
}
.sidebar-overlay.show { display: block; }

/* User menu */
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--clr-primary-light);
  color: #fff; display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; line-height: 1.2; }
.user-role {
  background: var(--clr-primary-soft);
  color: var(--clr-primary-dark);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  display: inline-block;
  white-space: nowrap;
}

/* Notification Bell */
.bell { position: relative; cursor: pointer; padding: 6px 8px; font-size: 18px; user-select: none; }
.bell .count {
  position: absolute;
  top: 0; right: 0;
  background: var(--clr-danger);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
  font-weight: 600;
  line-height: 1.4;
}

/* ================================ Cards ================================ */
.card {
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--clr-border);
  gap: 10px; flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--clr-text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--clr-primary-dark); line-height: 1.2; }
.kpi-unit { font-size: 13px; color: var(--clr-text-muted); margin-left: 4px; font-weight: 500; }

/* ================================ Forms ================================ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-weight: 600; font-size: 13px;
  margin-bottom: 6px; color: var(--clr-text);
}
.form-label .required { color: var(--clr-danger); font-size: 11px; margin-left: 4px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  font-family: inherit;
  /* iOS自動拡大防止のため16px以上 */
  font-size: 16px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  color: var(--clr-text);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-soft);
}
.form-input:disabled, .form-textarea:disabled, .form-select:disabled {
  background: #f0f3f5; color: #888; cursor: not-allowed;
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-help { font-size: 12px; color: var(--clr-text-muted); margin-top: 4px; line-height: 1.5; }
.form-error { font-size: 12px; color: var(--clr-danger); margin-top: 4px; }

.form-row { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-row > .form-group { margin-bottom: 0; }

/* ================================ Buttons ================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: all .12s;
  background: #fff;
  color: var(--clr-text);
  border-color: var(--clr-border);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }
.btn-primary:hover { background: var(--clr-primary-dark); border-color: var(--clr-primary-dark); color: #fff; }
.btn-danger { background: var(--clr-danger); color: #fff; border-color: var(--clr-danger); }
.btn-danger:hover { background: #a82e2e; color: #fff; }
.btn-outline { background: #fff; color: var(--clr-primary); border-color: var(--clr-primary); }
.btn-outline:hover { background: var(--clr-primary-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { display: flex; width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ================================ Tables ================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: #fff; border-radius: var(--radius);
  border: 1px solid var(--clr-border); margin-bottom: 18px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
.table th, .table td { padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--clr-border); vertical-align: middle; }
.table th { background: var(--clr-primary-tint); font-weight: 600; color: var(--clr-text);
  border-bottom: 1px solid var(--clr-border); white-space: nowrap; font-size: 12px; }
.table tbody tr:hover { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: none; }
.table .cell-right { text-align: right; }
.table .cell-center { text-align: center; }
.table .cell-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* テーブル内のフォーム要素をコンパクト化 */
.table .form-input, .table .form-select { font-size: 13px; padding: 5px 8px; }

/* ================================ Badges / Status ================================ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: #eef1f4;
  color: #4a5568;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}
.badge-primary { background: var(--clr-primary-soft); color: var(--clr-primary-dark); }
.badge-success { background: #d8f0e1; color: #0d5a29; }
.badge-warn { background: #fdf1d8; color: #8a550b; }
.badge-danger { background: #f9dcdc; color: #8a2525; }
.badge-info { background: #deebf8; color: #1d4a7c; }
.badge-muted { background: #e5e9ee; color: #586476; }

/* ================================ Alerts ================================ */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; line-height: 1.6; }
.alert-success { background: #d8f0e1; color: #0d5a29; border-left: 4px solid #1f7a3c; }
.alert-danger { background: #f9dcdc; color: #8a2525; border-left: 4px solid #d13a3a; }
.alert-warn { background: #fdf1d8; color: #8a550b; border-left: 4px solid #c97b15; }
.alert-info { background: #deebf8; color: #1d4a7c; border-left: 4px solid #2c6fbf; }
.alert a { color: inherit; text-decoration: underline; }

/* ================================ Tabs ================================ */
.tabs { display: flex; border-bottom: 2px solid var(--clr-border); margin-bottom: 20px;
  flex-wrap: wrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0; }
.tabs a {
  padding: 10px 18px;
  color: var(--clr-text-muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  text-decoration: none;
}
.tabs a.active { color: var(--clr-primary); border-bottom-color: var(--clr-primary); }
.tabs a:hover { text-decoration: none; color: var(--clr-primary-dark); }

/* ================================ Kanban ================================ */
.kanban { display: flex; gap: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: 12px; scroll-snap-type: x mandatory; }
.kanban-col {
  min-width: 240px;
  flex: 0 0 240px;
  background: #f0f3f5;
  border-radius: var(--radius);
  padding: 10px;
  scroll-snap-align: start;
}
.kanban-col-title {
  font-size: 12px; font-weight: 600; color: var(--clr-text);
  padding: 4px 6px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.kanban-col-count { background: var(--clr-primary); color: #fff; font-size: 10px;
  padding: 1px 7px; border-radius: 10px; }
.kanban-card {
  background: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  border-left: 3px solid var(--clr-primary);
  transition: box-shadow .12s;
}
.kanban-card:hover { box-shadow: var(--shadow-md); }
.kanban-card-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.kanban-card-meta { font-size: 11px; color: var(--clr-text-muted); }
.kanban-card-amount { font-size: 12px; color: var(--clr-primary-dark); font-weight: 600; margin-top: 2px; }

/* ================================ Chat ================================ */
.chat-root { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
.chat-panel {
  background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 480px;
  overflow: hidden;
}
.chat-header { padding: 12px 16px; border-bottom: 1px solid var(--clr-border);
  display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.chat-messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px; background: #f8fafb; }
.chat-bubble { margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.chat-bubble.own { flex-direction: row-reverse; }
.chat-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--clr-primary-light); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 13px; font-weight: 600;
}
.chat-bubble.admin .chat-avatar { background: #1f7a3c; }
.chat-bubble.partner .chat-avatar { background: #2c6fbf; }
.chat-bubble.client .chat-avatar { background: #c97b15; }
.chat-bubble.internal .chat-avatar { background: #8a550b; }

.chat-body { max-width: calc(100% - 50px); min-width: 0; }
.chat-meta { font-size: 11px; color: var(--clr-text-muted); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-bubble.own .chat-meta { text-align: right; }
.chat-text {
  background: #fff;
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--clr-border);
  font-size: 13px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.chat-bubble.own .chat-text {
  background: var(--clr-primary-soft);
  border-color: var(--clr-primary-light);
}
.chat-bubble.internal .chat-text {
  background: #fdf1d8;
  border: 1px dashed #c97b15;
}
.chat-internal-tag { font-size: 10px; background: #c97b15; color: #fff;
  padding: 1px 6px; border-radius: 3px; margin-right: 5px; }

.chat-input { padding: 12px 14px; border-top: 1px solid var(--clr-border); background: #fff;
  display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.chat-input .toolbar { display: flex; gap: 8px; align-items: center; font-size: 12px; flex-wrap: wrap; }
.chat-input textarea {
  width: 100%; border: 1px solid var(--clr-border);
  border-radius: 6px; padding: 8px 12px;
  font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 56px;
}
.chat-memo-toggle {
  font-size: 12px; color: var(--clr-warn);
  display: flex; align-items: center; gap: 4px;
}
.attach { font-size: 11px; color: var(--clr-primary);
  margin-top: 4px; display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: var(--clr-primary-soft);
  border-radius: 4px; }

/* Side panel */
.side-panel {
  background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 14px;
  height: fit-content;
  margin-bottom: 14px;
}
.side-panel h4 { margin-bottom: 8px; color: var(--clr-text);
  border-bottom: 1px solid var(--clr-border); padding-bottom: 6px; font-size: 13px; }
.side-panel ul { list-style: none; padding: 0; margin: 0; }
.side-panel ul li { padding: 6px 0; font-size: 13px; }

.progress-steps { list-style: none; padding: 0; margin: 0; }
.progress-steps li {
  padding: 6px 0 6px 20px;
  position: relative;
  font-size: 12px;
  color: var(--clr-text-muted);
}
.progress-steps li:before {
  content: ''; position: absolute; left: 0; top: 11px;
  width: 9px; height: 9px; border-radius: 50%;
  background: #d8dee5;
}
.progress-steps li.done { color: var(--clr-primary-dark); }
.progress-steps li.done:before { background: var(--clr-primary); }
.progress-steps li.current { color: var(--clr-primary-dark); font-weight: 600; }
.progress-steps li.current:before { background: var(--clr-primary); box-shadow: 0 0 0 3px var(--clr-primary-soft); }

/* ================================ Public pages ================================ */
.public-wrap { min-height: 100vh; background: var(--clr-bg);
  display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.public-card {
  background: #fff; padding: 32px 28px;
  border-radius: 12px; box-shadow: var(--shadow-md);
  width: 100%; max-width: 480px;
}
.public-wrap.wide .public-card { max-width: 720px; }
.public-card .logo {
  text-align: center; margin-bottom: 24px;
}
.public-card .logo-name {
  font-weight: 700; color: var(--clr-primary-dark); font-size: 18px;
}
.public-card .logo-sub { color: var(--clr-text-muted); font-size: 12px; margin-top: 4px; }
.public-footer { text-align: center; color: var(--clr-text-muted); font-size: 11px; margin-top: 16px; }

/* ================================ Login ================================ */
.login-title { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 24px; color: var(--clr-text); }

/* ================================ Notifications dropdown ================================ */
.notif-dropdown {
  position: absolute; top: calc(100% + 4px); right: 0;
  width: 360px; background: #fff;
  border: 1px solid var(--clr-border);
  border-radius: 8px; box-shadow: var(--shadow-md);
  max-height: 460px; overflow-y: auto;
  display: none; z-index: 200;
}
.notif-dropdown.open { display: block; }
.notif-dropdown .notif-item {
  padding: 12px 14px; border-bottom: 1px solid var(--clr-border); font-size: 13px;
  cursor: pointer; display: block; color: inherit; text-decoration: none;
}
.notif-dropdown .notif-item:hover { background: #f8fafb; text-decoration: none; }
.notif-dropdown .notif-item.unread { background: var(--clr-primary-tint); }
.notif-dropdown .notif-title { font-weight: 600; margin-bottom: 2px; }
.notif-dropdown .notif-time { font-size: 10px; color: var(--clr-text-muted); }

/* ================================ Pagination / Toolbar ================================ */
.toolbar { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.toolbar .form-input, .toolbar .form-select { width: auto; min-width: 0; }
.pagination { display: flex; gap: 4px; justify-content: center; margin: 16px 0;
  flex-wrap: wrap; }
.pagination a, .pagination span {
  display: inline-block; padding: 6px 12px;
  border: 1px solid var(--clr-border); border-radius: 4px;
  font-size: 13px; background: #fff; text-decoration: none; color: var(--clr-text);
}
.pagination a:hover { background: var(--clr-primary-soft); text-decoration: none; }
.pagination .active { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }

/* ================================ Calendar (月表示) ================================ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: #d8dee5; border: 1px solid #d8dee5; border-radius: 6px; overflow: hidden; }
.cal-hd { background: #f2faf6; text-align: center; padding: 6px 0;
  font-size: 12px; font-weight: 600; }
.cal-hd.sun { color: #c33; } .cal-hd.sat { color: #36c; }
.cal-cell { background: #fff; min-height: 90px; padding: 4px 6px; position: relative; overflow: hidden; }
.cal-cell.empty { background: #f7f9fb; }
.cal-cell .d { font-size: 11px; color: #666; }
.cal-cell.today .d { color: #1f7a3c; font-weight: 700; }
.cal-cell .ev { display: block; font-size: 11px; padding: 2px 4px; border-radius: 3px;
  margin-top: 2px;
  background: var(--clr-primary-soft); color: var(--clr-primary-dark);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; text-decoration: none; line-height: 1.4; }
.cal-cell .ev.zoom { background: #deebf8; color: #1d4a7c; }
.cal-cell .ev.google { background: #d8f0e1; color: #0d5a29; }
.cal-cell .ev.manual { background: #eef1f4; color: #4a5568; }
.cal-cell .ev.canceled { text-decoration: line-through; opacity: .5; }

/* ================================ Utilities ================================ */
.mt-0{margin-top:0}.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:16px}.mt-4{margin-top:24px}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:4px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:16px}.mb-4{margin-bottom:24px}
.text-muted { color: var(--clr-text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--clr-danger); }
.text-success { color: var(--clr-primary-dark); }
.fs-sm { font-size: 12px; }
.fs-xs { font-size: 11px; }
.fw-600 { font-weight: 600; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hide { display: none !important; }

/* ハンバーガーボタン(モバイル時のみ表示) */
.menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 22px; padding: 6px 10px; border-radius: 4px;
  color: var(--clr-text); line-height: 1;
  flex-shrink: 0;
}
.menu-toggle:hover { background: #f0f3f5; }

/* ================================ レスポンシブ ================================ */

/* タブレット (1024px以下) */
@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
  .app-main { padding: 16px 18px; }
  h1 { font-size: 20px; }
}

/* 中サイズ (900px以下): サイドバー隠す & ハンバーガー表示 */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header" "main";
  }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    height: 100vh;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .25s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open {
    transform: translateX(0);
    display: block;
  }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-close { display: inline-block; }
  .app-main { padding: 14px 12px; }

  .chat-root { grid-template-columns: 1fr; }
  .chat-panel { height: calc(100vh - 280px); min-height: 360px; order: 1; }
  .chat-root > div:not(.chat-panel) { order: 2; }

  .form-row, .form-row.cols-3 { grid-template-columns: 1fr; }

  .user-name, .user-role { display: none; }
  .app-header .header-right { gap: 8px; }
  .app-header { padding: 0 12px; }

  .table { min-width: 360px; }

  .cal-cell { min-height: 70px; padding: 2px 3px; }
  .cal-cell .ev { font-size: 10px; padding: 1px 3px; }

  .card { padding: 14px 14px; margin-bottom: 14px; }
  .card-header { gap: 8px; }
}

/* スマホ (560px以下) */
@media (max-width: 560px) {
  body { font-size: 13px; }
  .app-main { padding: 12px 10px; }
  .app-header { padding: 0 10px; }
  .app-header .page-title { font-size: 14px; }

  .card { padding: 12px 12px; border-radius: 6px; }
  .card-header h2 { font-size: 16px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 11px; }

  .table { font-size: 12px; }
  .table th, .table td { padding: 8px 8px; }

  .btn { padding: 10px 14px; min-height: 38px; }
  .btn-sm { padding: 6px 10px; min-height: 30px; font-size: 12px; }

  .cal-cell { min-height: 56px; }
  .cal-cell .ev { font-size: 9px; }
  .cal-hd { font-size: 11px; padding: 4px 0; }

  .kanban-col { min-width: 200px; flex: 0 0 200px; }

  .chat-bubble { gap: 8px; }
  .chat-avatar { width: 28px; height: 28px; font-size: 12px; }
  .chat-text { font-size: 13px; padding: 7px 11px; }
  .chat-input textarea { min-height: 48px; }

  .notif-dropdown { width: calc(100vw - 24px); right: -10px; }

  .tabs a { padding: 8px 12px; font-size: 13px; }

  .form-input, .form-select, .form-textarea { padding: 10px 12px; font-size: 16px; }

  .pagination a, .pagination span { padding: 8px 12px; min-width: 36px; min-height: 36px;
    display: inline-flex; align-items: center; justify-content: center; }

  .public-wrap { padding: 16px 8px; }
  .public-card { padding: 22px 18px; border-radius: 8px; }
}

/* プリント用 */
@media print {
  .app-sidebar, .app-header, .chat-input, .btn, .menu-toggle, .sidebar-overlay { display: none !important; }
  .app { grid-template-columns: 1fr; grid-template-areas: "main"; }
  .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
}
