/* Base */
:root { color-scheme: light dark; }
html, body { margin:0; padding:0; height:100%; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, "Hiragino Kaku Gothic ProN", Meiryo, "Noto Sans JP", sans-serif; }

body { display:flex; flex-direction: column; min-height: 100vh; }

.header { padding: 12px 16px; border-bottom: 1px solid #ddd; }
.header-bar{ display:flex; justify-content:space-between; align-items:center; }
.header-right{ display:flex; align-items:center; }
.user-link{
    display:inline-flex; align-items:center; justify-content:center;
    width:28px; height:28px; border-radius:50%;
    background:#e0e6f0; color:#445; text-decoration:none; margin-right:8px;
}
.user-email{ color:#666; margin-right:15px; }

/* ===== User status badge ===== */
.status-badge{
    display:inline-block;
    padding:4px 8px;
    border-radius:999px;
    font-size:12px;
    font-weight:700;
    margin-right:8px;
    line-height:1;
}
.status-badge.is-active{ background:#e6f6ec; color:#1b7f3b; border:1px solid #bfe6cb; }
.status-badge.is-trial{ background:#fff5d6; color:#8a5b00; border:1px solid #f3e1a6; }
.status-badge.is-cancelled{ background:#f4e6e8; color:#8a1b2e; border:1px solid #e5bcc3; }

@media (prefers-color-scheme: dark){
    .status-badge.is-active{ background:#11331f; color:#90e0a8; border-color:#1f5b37; }
    .status-badge.is-trial{ background:#2f2a15; color:#ffd776; border-color:#594f24; }
    .status-badge.is-cancelled{ background:#3a2026; color:#ffb5c1; border-color:#5b333c; }
}
.container { max-width: none; margin: 0; padding: 0; display:flex; flex-direction: column; flex: 1 1 auto; }
.toolbar { margin-bottom: 12px; display:flex; gap:8px; align-items: center; }
.sel-count { margin-left: 6px; color:#1f3a73; font-weight: 600; }
.pager { margin-left: auto; display:flex; align-items: center; gap: 8px; }
.pager-info { color:#52607a; font-size: 13px; }
.pager-buttons { display:flex; gap:6px; }
.btn { display:inline-flex; align-items:center; justify-content:center; height:28px; padding:0 12px; border-radius: 6px; text-decoration: none; color:#1f3a73; background:#e7eefc; border:1px solid #b7c6ee; font-size:14px; line-height:1; margin-top:6px; margin-left:6px; }
.btn:hover { background:#f2f6ff; }
.pager .btn { width:28px; padding:0; }
.pager .btn.disabled { pointer-events:none; opacity:0.4; }

/* 削除ボタン */
/* 削除ボタン（共通ボタンと同形） */
button.danger { background:#e7eefc; color:#1f3a73; border:1px solid #b7c6ee; border-radius:6px; padding:0 12px; height:28px; }
button.danger:hover { background:#f2f6ff; }

.container > section:last-of-type { flex: 1 1 auto; overflow: auto; }
.container > section:last-of-type { -webkit-overflow-scrolling: touch; }

.mail-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.mail-table { min-width: 680px; }
.mail-table th, .mail-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-table th, .mail-table td { border-bottom: 1px solid #e5e5e5; padding: 8px 10px; }
/* 項目間の縦区切り線を濃く */
.mail-table thead th + th { border-left: 1px solid #b7c6ee; }
.mail-table th { text-align: left; background: #f9f9f9; }
.mail-table thead th { position: sticky; top: 0; z-index: 2; background: #e2ecff; font-weight: 400; border-bottom: 2px solid #9fb7e5; box-shadow: 0 2px 0 rgba(0,0,0,0.06); }
.mail-table thead th.sortable { cursor: pointer; user-select: none; }
.mail-table thead th.sortable::after { content: '\25B4\25BE'; font-size: 10px; margin-left: 6px; opacity: 0.4; }
.mail-table thead th.sortable[data-order="asc"]::after { content: '\25B4'; opacity: 1; }
.mail-table thead th.sortable[data-order="desc"]::after { content: '\25BE'; opacity: 1; }
.mail-table thead th.sortable[data-order="asc"],
.mail-table thead th.sortable[data-order="desc"] { font-weight: 700; }

/* 3D/立体的な見た目 */
.mail-table thead th.sortable {
  background:
    linear-gradient(180deg, #f6f9ff 0%, #e5eeff 60%, #d7e4ff 100%),
    linear-gradient(#b7c6ee, #b7c6ee) left 6px center / 1px 60% no-repeat,
    linear-gradient(#b7c6ee, #b7c6ee) right 6px center / 1px 60% no-repeat;
  box-shadow: 0 1px 0 #ffffff inset, 0 1px 2px rgba(0,0,0,0.08);
}
.mail-table thead th.sortable:hover {
  background:
    linear-gradient(180deg, #ffffff 0%, #eaf1ff 60%, #dbe7ff 100%),
    linear-gradient(#b7c6ee, #b7c6ee) left 6px center / 1px 60% no-repeat,
    linear-gradient(#b7c6ee, #b7c6ee) right 6px center / 1px 60% no-repeat;
  box-shadow: 0 1px 0 #ffffff inset, 0 2px 4px rgba(0,0,0,0.10);
}
.mail-table thead th.sortable:active {
  background:
    linear-gradient(180deg, #eaf1ff 0%, #dbe7ff 60%, #cbdcff 100%),
    linear-gradient(#b7c6ee, #b7c6ee) left 6px center / 1px 60% no-repeat,
    linear-gradient(#b7c6ee, #b7c6ee) right 6px center / 1px 60% no-repeat;
  box-shadow: 0 2px 0 rgba(0,0,0,0.06) inset;
}
.mail-table thead th.sortable:focus-visible {
  outline: 2px solid #7aa2f7;
  outline-offset: -2px;
}
.mail-table tbody tr:hover { background: #f5fafe; }
.mail-table tbody tr:nth-child(even) { background: #fafcff; }

.mail-table th:nth-child(1), .mail-table td:nth-child(1) { width: 40px; text-align: center; padding-left: 4px; padding-right: 4px; }
.mail-table th:nth-child(2), .mail-table td:nth-child(3) { width: auto; }
.mail-table th:nth-child(3), .mail-table td:nth-child(4) { width: 500px; }
.mail-table th:nth-child(4), .mail-table td:nth-child(5) { width: 200px; }

/* Responsive */
@media (max-width: 1024px) {
	.toolbar { flex-wrap: wrap; row-gap: 8px; }
	.pager { margin-left: 0; }
	.mail-table th, .mail-table td { padding: 6px 8px; }
	.mail-table th:nth-child(3), .mail-table td:nth-child(4) { width: 300px; }
	.mail-table th:nth-child(4), .mail-table td:nth-child(5) { width: 180px; }
}

@media (max-width: 768px) {
	.header { padding: 10px 12px; }
	.toolbar { gap: 6px; }
	.btn { height: 30px; padding: 0 10px; }
	.pager-info { font-size: 12px; }
	.mail-table th:nth-child(1), .mail-table td:nth-child(1) { width: 32px; }
	.mail-table th:nth-child(3), .mail-table td:nth-child(4) { width: 300px; }
	.mail-table th:nth-child(4), .mail-table td:nth-child(5) { width: 160px; }
}

@media (max-width: 600px) {
	.mail-table { min-width: 600px; }
	.mail-table th, .mail-table td { padding: 5px 6px; }
	.pager { width: 100%; justify-content: space-between; }
	/* テーブルをカード状の複数行表示に切替 */
	.container > section:last-of-type { overflow: visible; }
	.mail-table { min-width: 0; table-layout: auto; }
	.mail-table thead { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }
	.mail-table tbody, .mail-table tr, .mail-table td { display: block; }
	.mail-table tbody tr { margin: 8px 0; border: 1px solid #e5e5e5; border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
	.mail-table tbody tr:hover { background: #fff; }
	.mail-table td { border: 0; padding: 6px 8px; display: grid; grid-template-columns: 110px 1fr; align-items: center; justify-items: start; white-space: normal; overflow: visible; text-overflow: initial; }
	/* Check 行は左寄せ */
	.mail-table td:nth-child(2) { text-align: left; }
	.mail-table td:nth-child(1) { text-align: left; }
	/* ラベル表示 */
	.mail-table td::before { content: attr(data-label); font-weight: 600; color: #52607a; margin-right: 0; }
	/* data-labelが無くても列ごとにフォールバック */
	.mail-table td:nth-child(1)::before { content: 'No.'; }
	.mail-table td:nth-child(2)::before { content: 'Subject'; }
	.mail-table td:nth-child(3)::before { content: 'FromAddress'; }
	.mail-table td:nth-child(4)::before { content: 'DateTime'; }
	/* 文字を左寄せ */
	.mail-table td:nth-child(3),
	.mail-table td:nth-child(4) { text-align: left; }
	/* 固定幅解除 */
	.mail-table th, .mail-table td { width: auto !important; }
}

/* ログインリンクスタイル */
.login-link {
	display: inline-block;
	background: #4caf50;
	color: white;
	text-decoration: none;
	padding: 10px 20px;
	border-radius: 5px;
	font-weight: bold;
	transition: background-color 0.3s ease;
}

.login-link:hover {
	background: #45a049;
	color: white;
	text-decoration: none;
}

/* Auth pages: below-button text links (login/signup) */
.signup-link { text-align: center; margin-top: 24px; }
.signup-link a { color: #667eea; text-decoration: none; font-weight: 500; font-size: 14px; }
.signup-link a:hover { text-decoration: underline; }

/* ===== Auth/Confirm pages (moved from inline CSS) ===== */
.login-container,
.signup-container,
.confirm-container {
	display: flex;
	justify-content: center;
	align-items: center;
	min-height: 100vh;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box,
.signup-box,
.confirm-box {
	background: white;
	padding: 40px;
	border-radius: 12px;
	box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
	width: 100%;
    max-width: 400px;
    color: #1b2130; /* カード内の本文テキスト色を強制（ダークモードでも可読） */
}

/* Responsive: add 6px side margins for auth pages */
@media (max-width: 600px) {
    .login-container,
    .signup-container,
    .confirm-container {
        padding-left: 6px;
        padding-right: 6px;
    }
}

/* ===== Shared header logo styles ===== */
.site-title{ margin:0; display:flex; align-items:center; gap:10px; }
.site-title .logo{ width:28px; height:28px; border-radius:6px; display:block; }

.login-title,
.signup-title,
.title {
	text-align: center;
	margin-bottom: 30px;
	color: #333;
	font-size: 24px;
	font-weight: 600;
}

.form-group { margin-bottom: 20px; }
.form-label { display: block; margin-bottom: 8px; color: #555; font-weight: 500; }
.label-sm { font-size: 13px; }
.form-input {
	width: 100%;
	padding: 12px 16px;
	border: 2px solid #e1e5e9;
	border-radius: 8px;
	font-size: 16px;
	transition: border-color 0.3s ease;
	box-sizing: border-box;
    color: #1b2130; /* 入力文字色（白背景で可読） */
    background: #ffffff;
}
.form-input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.1); }
/* プレースホルダーも可読に */
.form-input::placeholder { color: #98a1b3; }

.login-btn,
.signup-btn,
.confirm-btn,
.btn-primary {
	width: 100%;
	padding: 14px;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	border: none;
	border-radius: 8px;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: transform 0.2s ease;
	display: inline-block;
	text-decoration: none;
	text-align: center;
	box-sizing: border-box;
}
.login-btn:hover,
.signup-btn:hover,
.confirm-btn:hover,
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(102,126,234,0.3); }

.message { font-size: 15px; line-height: 1.8; color: #333; }
.actions { margin-top: 24px; text-align: center; }

.error-message { background: #f8d7da; color: #721c24; padding: 10px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #f5c6cb; }
.success-message { background: #d4edda; color: #155724; padding: 10px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #c3e6cb; }
.info-message { background: #e3f2fd; color: #1565c0; padding: 10px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #bbdefb; }
.debug-message { background: #fff3e0; color: #e65100; padding: 12px; border-radius: 6px; margin-bottom: 20px; border: 1px solid #ffcc02; font-family: monospace; font-size: 12px; max-height: 200px; overflow-y: auto; }

/* ===== Shared: login/signup logos on auth cards ===== */
.login-box{ position: relative; }
.login-logo{ position: absolute; top: 12px; left: 12px; display: block; }
.login-logo img{ width: 46px; height: 46px; border-radius: 10px; display: block; }
.login-title{ margin-left: 68px; min-height: 46px; display: flex; align-items: center; }

/* Auth: trial badge (used on signup card) */
.trial-badge{
	display:inline-block;
	margin: 0 0 10px 0;
	padding: 8px 12px;
	border-radius: 999px;
	font-weight: 700;
	font-size: 14px;
	letter-spacing: .04em;
	background: linear-gradient(135deg, #ffe66d, #ffb703);
	color: #1a1a1a;
	box-shadow: 0 10px 24px rgba(255,183,3,.28);
}

/* ===== Dark mode overrides ===== */
@media (prefers-color-scheme: dark){
    body{ background:#0f1115; color:#e6e7eb; }
    .header{ border-bottom-color:#2a2f3a; }
    .container > section:last-of-type{ background:transparent; }

    /* Buttons */
    .btn{ background:#1a2333; color:#d6ddf5; border-color:#31446b; }
    .btn:hover{ background:#20304a; }
    button.danger{ background:#2a1f24; color:#ffd7dc; border-color:#53414a; }
    button.danger:hover{ background:#34262c; }

    /* Tables */
    .mail-table th, .mail-table td{ border-bottom:1px solid #2a2f3a; }
    .mail-table thead th{ background:#172031; color:#d9e1ff; border-bottom:2px solid #2d3d63; box-shadow:none; }
    .mail-table thead th + th{ border-left:1px solid #2a2f3a; }
    .mail-table thead th.sortable{ background:linear-gradient(180deg, #19243a 0%, #152132 100%); box-shadow:0 1px 0 rgba(255,255,255,0.03) inset, 0 1px 2px rgba(0,0,0,0.24); }
    .mail-table thead th.sortable:hover{ background:linear-gradient(180deg, #1b2a45 0%, #18253a 100%); }
    .mail-table tbody tr:hover{ background:#131a28; }
    .mail-table tbody tr:nth-child(even){ background:#0f1624; }
    .mail-table tbody tr{ background:transparent; }

    /* Header title and logo */
    .site-title .logo{ box-shadow:0 0 0 1px rgba(255,255,255,0.06) inset; }

    /* Auth cards on dark mode: keep cards light for contrast */
    .login-box,
    .signup-box,
    .confirm-box { background:#ffffff; color:#1b2130; }
    .login-title,
    .signup-title,
    .title { color:#1b2130; }
    .form-input { background:#ffffff; color:#1b2130; border-color:#d7dbe2; }
    .form-input::placeholder { color:#98a1b3; }
    .error-message{ background:#3b1216; color:#ffd9de; border-color:#6a2230; }
    .success-message{ background:#12351d; color:#c9f0d6; border-color:#1f5c33; }
    .info-message{ background:#0e2847; color:#cfe2ff; border-color:#1b4175; }
}