/* =========================================================
   Mail Console - Refined Corporate UI (v2)
   Goals: clarity on PC, comfortable touch targets on mobile,
          consistent spacing/typography, subtle motion.
   ========================================================= */

:root {
  /* ----- Color tokens ----- */
  --primary:        #1e40af;
  --primary-hover:  #1d4ed8;
  --primary-active: #1e3a8a;
  --primary-light:  #eff6ff;
  --primary-border: #bfdbfe;
  --primary-strong: #1e3a8a;

  --accent:         #0ea5e9;   /* used sparingly */
  --accent-light:   #e0f2fe;

  --bg:             #f4f6fb;   /* page background */
  --bg-deep:        #eef1f7;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --surface-3:      #f1f5f9;
  --sidebar-bg:     #ffffff;
  --topbar-bg:      #ffffff;

  --border:         #e5e7eb;
  --border-strong:  #d1d5db;
  --divider:        #eef0f4;

  --text-primary:   #0f172a;
  --text-secondary: #334155;
  --text-muted:     #64748b;
  --text-subtle:    #94a3b8;
  --text-on-primary:#ffffff;

  --success:    #047857;
  --success-bg: #ecfdf5;
  --success-bd: #a7f3d0;
  --warning:    #b45309;
  --warning-bg: #fffbeb;
  --warning-bd: #fde68a;
  --danger:     #b91c1c;
  --danger-bg:  #fef2f2;
  --danger-bd:  #fecaca;
  --info:       #1e40af;
  --info-bg:    #eff6ff;
  --info-bd:    #bfdbfe;

  /* ----- Shadows ----- */
  --shadow-xs: 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow:    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 8px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 24px -8px rgba(15, 23, 42, 0.14), 0 4px 10px -4px rgba(15, 23, 42, 0.06);
  --shadow-focus: 0 0 0 3px rgba(30, 64, 175, 0.18);

  /* ----- Radii ----- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius:    8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 9999px;

  /* ----- Spacing scale ----- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10:40px;

  /* ----- Motion ----- */
  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur:      180ms;
  --dur-slow: 260ms;

  /* ----- Layout ----- */
  --sidebar-w:     248px;
  --topbar-h:      60px;
  --footer-tab-h:  64px;
  --content-max:   1320px;
}

/* ============ Base reset / typography ============ */
* { box-sizing: border-box; }

body, p, h1, h2, h3, h4, h5, h6, div, span, a, button, input, textarea, select, label, li {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body { margin: 0; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { color: var(--primary-hover); }

button { font-family: inherit; }

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

/* selection */
::selection {
  background: var(--primary-light);
  color: var(--primary-strong);
}

/* ============ App layout ============ */
.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 10px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  padding: 0 10px 6px;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}

.sidebar-link i {
  width: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease);
}

.sidebar-link:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.sidebar-link:hover i { color: var(--text-primary); }

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary-strong);
  font-weight: 600;
}
.sidebar-link.active i { color: var(--primary); }

/* Left accent indicator on active link */
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.sidebar-link-badge {
  margin-left: auto;
  font-size: 10.5px;
  background: var(--surface-3);
  color: var(--text-muted);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  font-weight: 600;
}
.sidebar-link.active .sidebar-link-badge {
  background: var(--primary);
  color: #fff;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--divider);
  font-size: 11px;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-footer i { color: var(--success); font-size: 8px; }

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

/* ============ Topbar ============ */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 25;
  min-height: var(--topbar-h);
  backdrop-filter: saturate(180%) blur(8px);
  background: rgba(255, 255, 255, 0.92);
}

.topbar-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease);
}
.topbar-menu-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.topbar-menu-btn:active { background: var(--surface-3); }

.topbar-titles {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-title-icon {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.topbar-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ============ Content area ============ */
.content {
  flex: 1;
  padding: 28px;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

/* ============ Panel / Card ============ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.panel-title i { color: var(--text-muted); }

.panel-body { padding: 18px; }

/* Legacy compat */
.glass-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

/* ============ Tiles (menu) ============ */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.menu-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  text-decoration: none;
  transition: transform var(--dur) var(--ease-out),
              border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  overflow: hidden;
}
.menu-tile::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--surface-3);
  transition: background var(--dur-fast) var(--ease);
}
.menu-tile:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: var(--text-primary);
}
.menu-tile:hover::after { background: var(--primary); }

.menu-tile-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 18px;
  transition: transform var(--dur) var(--ease-out);
}
.menu-tile:hover .menu-tile-icon { transform: scale(1.05); }

.menu-tile-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.menu-tile-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}
.menu-tile-arrow {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease), gap var(--dur-fast) var(--ease);
}
.menu-tile:hover .menu-tile-arrow {
  color: var(--primary);
  gap: 10px;
}

/* ============ Buttons ============ */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              transform 80ms var(--ease);
  border-radius: var(--radius);
  user-select: none;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  box-shadow: 0 1px 2px rgba(30, 64, 175, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px -2px rgba(30, 64, 175, 0.35);
}
.btn-primary:active:not(:disabled) {
  background: var(--primary-active);
  border-color: var(--primary-active);
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(30, 64, 175, 0.2);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-subtle);
  color: var(--text-primary);
}
.btn-secondary:active:not(:disabled) {
  background: var(--surface-3);
  transform: translateY(1px);
}
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
  background: var(--surface);
  border: 1px solid var(--danger-bd);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: #fca5a5;
}
.btn-danger:active:not(:disabled) { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-primary);
}

/* Icon-only button */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

/* ============ Forms ============ */
.input-field,
input[type="text"].input-field,
input[type="email"].input-field,
input[type="password"].input-field,
input[type="number"].input-field,
textarea.input-field,
select.input-field {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
  border-radius: var(--radius);
  font-size: 13.5px;
}

.input-field:hover:not(:focus):not(:disabled) {
  border-color: var(--text-subtle);
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}

.input-field::placeholder {
  color: var(--text-subtle);
}

.input-field:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

textarea.input-field {
  line-height: 1.6;
  resize: vertical;
}

label { color: var(--text-secondary); }

/* Search input wrapper */
.input-search {
  position: relative;
}
.input-search > input {
  padding-left: 36px;
}
.input-search > i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  font-size: 13px;
  pointer-events: none;
}

/* ============ Checkbox (custom) ============ */
.custom-checkbox {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  transition: all var(--dur-fast) var(--ease);
  flex-shrink: 0;
}
.custom-checkbox:hover:not(:disabled) {
  border-color: var(--primary);
}
.custom-checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.custom-checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
}
.custom-checkbox:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
  background-clip: content-box;
}

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid;
  white-space: nowrap;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

.badge-success { background: var(--success-bg); color: var(--success); border-color: var(--success-bd); }
.badge-pending { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-bd); }
.badge-failed  { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-bd); }
.badge-info    { background: var(--info-bg);    color: var(--info);    border-color: var(--info-bd); }
.badge-neutral { background: var(--surface-3);  color: var(--text-secondary); border-color: var(--border); }

/* ============ Spinner ============ */
.spinner {
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Toast ============ */
.toast {
  animation: toast-in 0.22s var(--ease-out);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
}
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============ Modal ============ */
.modal-overlay {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  animation: modal-in var(--dur-slow) var(--ease-out);
  box-shadow: var(--shadow-lg) !important;
  border-radius: var(--radius-lg) !important;
}
@keyframes modal-in {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ============ Tables ============ */
.data-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th {
  background: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--divider);
  color: var(--text-primary);
  font-size: 13px;
}

.data-table tbody tr {
  transition: background var(--dur-fast) var(--ease);
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ============ Variable chips ============ */
.var-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  margin: 1px 2px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--primary-strong);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  user-select: none;
}
.var-chip:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  transform: translateY(-1px);
}
.var-chip:active { transform: translateY(0); }

/* ============ File items ============ */
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
  border: 1px solid transparent;
}
.file-item:hover { background: var(--surface-2); }
.file-item.selected {
  background: var(--primary-light);
  border-color: var(--primary-border);
}

/* ============ Section header ============ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

/* ============ Form group ============ */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-help {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============ Stat cards ============ */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform var(--dur) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: #d4dbe6;
}
.stat-card-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-card-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-card-icon.green  { background: var(--success-bg);   color: var(--success); }
.stat-card-icon.amber  { background: var(--warning-bg);   color: var(--warning); }
.stat-card-icon.sky    { background: var(--accent-light); color: var(--accent); }

.stat-card-body { min-width: 0; flex: 1; }
.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  line-height: 1.4;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.stat-value.text-small { font-size: 13px; padding-top: 6px; }

/* ============ Empty state ============ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon {
  font-size: 36px;
  color: var(--text-subtle);
  margin-bottom: 12px;
  opacity: 0.6;
}
.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.empty-state-desc {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto;
}

/* ============ Avatar ============ */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }

/* ============ Compose page layout ============ */
.compose-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.compose-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.contact-list-scroll {
  max-height: calc(100vh - 320px);
  min-height: 280px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

/* Compose contact row */
.compose-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
  border: 1px solid transparent;
}
.compose-contact:hover { background: var(--surface-2); }
.compose-contact.selected {
  background: var(--primary-light);
  border-color: var(--primary-border);
}

/* Mobile tabs */
.compose-mobile-tabs {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
  gap: 4px;
}

.compose-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.compose-tab i { font-size: 13px; }
.compose-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px -2px rgba(30, 64, 175, 0.4);
}
.compose-tab.active i { color: #fff; }

.compose-tab-badge {
  background: var(--surface-3);
  color: var(--text-secondary);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}
.compose-tab.active .compose-tab-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* Compose action bar */
.compose-action-bar {
  position: sticky;
  bottom: 12px;
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-md);
  z-index: 10;
}

/* Per-contact attachment row */
.per-contact-att-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

/* ============ Footer Tab Bar (Mobile) - FAB style ============ */
.footer-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  z-index: 45;
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  align-items: center;
  justify-content: space-between;
}

/* 左右のサイド(各2アイテム) */
.footer-tab-side {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-around;
}

.footer-tab-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 54px;
  height: 48px;
  border-radius: 10px;
  transition:
    color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.footer-tab-item i {
  font-size: 18px;
  line-height: 1;
  transition: transform var(--dur) var(--ease-out);
}
.footer-tab-item span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0.85;
}

.footer-tab-item:active {
  transform: scale(0.94);
  background: rgba(30, 64, 175, 0.06);
}

.footer-tab-item.active {
  color: var(--primary);
}
.footer-tab-item.active i {
  color: var(--primary);
}
.footer-tab-item.active span {
  opacity: 1;
}

/* 中央のFAB(作成) - バー内に収まるフラット円形 */
.footer-tab-fab {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
  margin: 0 8px;
  transition:
    transform var(--dur) var(--ease-out),
    background var(--dur) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.footer-tab-fab i {
  font-size: 18px;
  color: #fff;
  transition: transform var(--dur) var(--ease-out);
}
.footer-tab-fab:hover {
  background: var(--primary-strong);
  color: #fff;
}
.footer-tab-fab:active {
  transform: scale(0.95);
}
.footer-tab-fab:active i {
  transform: rotate(-10deg);
}
.footer-tab-fab.active {
  background: var(--primary-strong);
}

/* ============ More menu sheet ============ */
.more-menu-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 60;
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur) var(--ease-out);
}
.more-menu-backdrop.open { display: block; }

.more-menu-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 12px 20px 24px;
  box-shadow: var(--shadow-lg);
  z-index: 61;
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
}
.more-menu-sheet.open { transform: translateY(0); }

.more-menu-handle {
  width: 40px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.more-menu-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  text-align: center;
  letter-spacing: -0.01em;
}
.more-menu-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.more-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: all var(--dur-fast) var(--ease);
}
.more-menu-item:active {
  transform: scale(0.97);
}
.more-menu-item:hover,
.more-menu-item.active {
  border-color: var(--primary-border);
  background: var(--primary-light);
  color: var(--primary-strong);
}
.more-menu-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  transition: all var(--dur-fast) var(--ease);
}
.more-menu-item:hover .more-menu-icon,
.more-menu-item.active .more-menu-icon {
  background: #fff;
  color: var(--primary);
}
.more-menu-label {
  font-size: 12px;
  font-weight: 600;
}
.more-menu-close {
  width: 100%;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.more-menu-close:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

/* ============ Sidebar backdrop ============ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade-in var(--dur) var(--ease-out);
}

/* ============ Sticky footer (page actions) ============ */
.page-action-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* ============ Utility ============ */
.divider { border-top: 1px solid var(--divider); }
.text-muted-app { color: var(--text-muted); }
.gradient-text { color: var(--text-primary); }

.kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
  .content { padding: 22px; }
  .hero { padding: 24px; }
  .hero-title { font-size: 20px; }
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: 280px;
  }
  .sidebar {
    position: fixed;
    left: calc(var(--sidebar-w) * -1 - 8px);
    top: 0;
    width: var(--sidebar-w);
    transition: left var(--dur-slow) var(--ease-out);
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar-backdrop.open { display: block; }

  .topbar {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.96);
  }
  .topbar-menu-btn { display: inline-flex; }
  .topbar-title { font-size: 16px; }
  .topbar-subtitle { font-size: 11.5px; }

  .content {
    /* フッタータブ(固定型:height 60px)+余白で被り防止 */
    padding: 16px 14px 76px;
  }

  .footer-tab-bar { display: flex; }

  /* Tiles */
  .tile-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .menu-tile { padding: 14px; gap: 8px; }
  .menu-tile-title { font-size: 13.5px; }
  .menu-tile-desc { font-size: 11.5px; -webkit-line-clamp: 2; }
  .menu-tile-icon { width: 36px; height: 36px; font-size: 16px; }

  /* Stats */
  .stat-card { padding: 14px; gap: 10px; }
  .stat-card-icon { width: 38px; height: 38px; font-size: 16px; }
  .stat-value { font-size: 19px; }

  /* Larger touch targets */
  .btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    min-height: 40px;
  }
  .input-field {
    min-height: 42px;
  }
  .panel-header { padding: 12px 14px; }
  .panel-body { padding: 14px; }

  /* Tables become cards (optional class) */
  .data-table.responsive thead { display: none; }
  .data-table.responsive tr {
    display: block;
    border-bottom: 1px solid var(--divider);
    padding: 10px 0;
  }
  .data-table.responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: none;
    padding: 6px 14px;
    font-size: 13px;
  }
  .data-table.responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .section-header { gap: 8px; }
  .section-title { font-size: 14.5px; }

  /* Compose: switch to single-column tabs */
  .compose-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .compose-right { gap: 0; }
  .compose-mobile-tabs { display: flex; }
  /* デフォルト: 宛先のみ表示。JS で .pane-active を切り替え */
  .compose-pane { display: none; }
  #pane-recipients { display: block; }  /* 初期表示 */
  .compose-pane.pane-active { display: block; }
  /* 別ペインが active になったら recipients を隠す */
  body:has(.compose-pane.pane-active) #pane-recipients:not(.pane-active) { display: none; }

  .contact-list-scroll { max-height: 60vh; }

  .compose-action-bar {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: 92px;  /* フッタータブ(浮遊型)の上に配置 */
    margin-top: 0;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
  }
  .compose-action-bar > div:first-child { font-size: 12.5px; }
}

@media (max-width: 480px) {
  .tile-grid { grid-template-columns: 1fr; }
  .menu-tile {
    flex-direction: row;
    align-items: center;
    padding: 14px;
  }
  .menu-tile-icon { width: 40px; height: 40px; }
  .menu-tile-arrow {
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
  }
  .menu-tile-body { flex: 1; min-width: 0; }

  .footer-tab-item span { font-size: 10px; }
  .footer-tab-item i { font-size: 17px; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
