/* =============================================================================
   common.css : デザインシステムの中核
   -----------------------------------------------------------------------------
   デザインコンセプト:
     明るく親しみやすい「ポップで可愛らしい」アイドルテイスト。
     ベース=ピンク/ホワイト/ライトグレー、アクセント=パステル3色。
     長時間の業務利用に耐える、彩度を抑えた柔らかい配色。
   構成:
     1. デザイントークン（配色/角丸/影/余白/タイポ） 2. リセット
     3. タイポグラフィ 4. アイコン 5. ボタン 6. フォーム 7. カード
     8. トースト 9. ユーティリティ/アクセシビリティ
   ============================================================================= */

/* ============================ 1. デザイントークン ========================= */
:root {
    /* --- ベースカラー（ピンク階調） --- */
    --pink-50:  #fff5f9;
    --pink-100: #ffe6f1;
    --pink-200: #ffd0e4;
    --pink-300: #ffb2d2;
    --pink-400: #ff8dbc;
    --pink-500: #f56aa4;   /* ブランド主要色 */
    --pink-600: #e24d8c;   /* 濃いピンク（押下・強調） */
    --pink-700: #c23a75;

    /* --- パステルアクセント --- */
    --pastel-pink:   #ffd9e8;
    --pastel-yellow: #fff0b8;
    --pastel-blue:   #cfe6ff;
    --accent-yellow: #ffd54a;
    --accent-blue:   #7cc0ff;

    /* --- 状態色（成功/警告/危険） --- */
    --success: #2fae60;   --success-soft: #dbf3e4;
    --warning: #f39323;   --warning-soft: #ffedd6;
    --danger:  #e5384d;   --danger-soft:  #ffe0e4;

    /* --- 面と背景 --- */
    --bg:         linear-gradient(160deg, #fff5f9 0%, #f3f1f7 55%, #eef1f8 100%);
    --surface:    #ffffff;                    /* 不透明カード面 */
    --surface-2:  #faf7fb;                    /* 一段沈んだ面 */
    --frost:      rgba(255, 255, 255, 0.72);  /* すりガラス面 */
    --border:     #f0dfe9;                     /* 淡いピンク寄りの境界 */
    --border-2:   #e7e2ee;

    /* --- テキスト（可読性最優先・コントラスト確保） --- */
    --text:        #2e2833;   /* 本文（対白 約12:1） */
    --text-muted:  #7b7387;   /* 補助（対白 約4.7:1） */
    --text-onbrand:#ffffff;   /* ブランド色上の文字 */

    /* --- ブランド別名（意味で参照） --- */
    --brand:        var(--pink-500);
    --brand-strong: var(--pink-600);
    --focus-ring:   #6aa6ff;   /* フォーカスは青系で明確に */

    /* --- 角丸 --- */
    --r-xs: 8px;  --r-sm: 12px;  --r: 16px;  --r-lg: 22px;  --r-pill: 999px;

    /* --- 影（ピンク寄りの柔らかい影） --- */
    --shadow-sm: 0 1px 2px rgba(226, 77, 140, 0.08), 0 1px 3px rgba(46, 40, 51, 0.06);
    --shadow:    0 6px 18px rgba(226, 77, 140, 0.10), 0 2px 6px rgba(46, 40, 51, 0.06);
    --shadow-lg: 0 18px 44px rgba(226, 77, 140, 0.16), 0 6px 16px rgba(46, 40, 51, 0.08);
    --shadow-pop:0 24px 60px rgba(46, 40, 51, 0.24);

    /* --- タイポグラフィ（日本語優先の可読フォント） --- */
    --font-base: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Hiragino Sans",
                 "Meiryo", system-ui, -apple-system, "Segoe UI", sans-serif;
    --fs-h1: 22px;  --fs-h2: 17px;  --fs-h3: 14px;
    --fs-body: 14px;  --fs-label: 12px;  --fs-btn: 13px;  --fs-mini: 11px;
    --lh: 1.6;

    /* --- モーション --- */
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-pop: cubic-bezier(0.2, 0.9, 0.3, 1.25);
    --dur: 0.16s;  --dur-lg: 0.26s;

    /* キャンバス関連（canvas.cssが参照） */
    --canvas-bg: #efe9f1;
    --page-bg: #ffffff;
    --ruler-bg: #fbf3f7;
    --grid-line: rgba(245, 106, 164, 0.18);
    --grid-line-strong: rgba(245, 106, 164, 0.34);
}

/* ---- ダークテーマ（同じ意味トークンを上書き） --------------------------- */
:root[data-theme="dark"] {
    --pink-500: #ff8fbf;  --pink-600: #ff6fa8;

    --bg:        linear-gradient(160deg, #1d1824 0%, #191320 55%, #15121d 100%);
    --surface:   #262030;
    --surface-2: #2e2739;
    --frost:     rgba(38, 32, 48, 0.66);
    --border:    #3a3247;
    --border-2:  #423a50;

    --text:       #f3ecf7;
    --text-muted: #b4a9c2;

    --success-soft: #16332363; --warning-soft: #3a2a1563; --danger-soft: #3a1c2263;
    --focus-ring: #8fbaff;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow:    0 8px 22px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
    --shadow-pop:0 28px 64px rgba(0, 0, 0, 0.6);

    --canvas-bg: #14101c;
    --page-bg:   #f8f6fb;   /* 用紙は白基調のまま（印刷イメージ維持） */
    --ruler-bg:  #221b2c;
    --grid-line: rgba(255, 143, 191, 0.20);
    --grid-line-strong: rgba(255, 143, 191, 0.36);
}

/* ============================ 2. リセット ================================= */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: var(--font-base);
    font-size: var(--fs-body);
    line-height: var(--lh);
    color: var(--text);
    background: var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
ul, ol { list-style: none; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

/* ============================ 3. タイポグラフィ =========================== */
h1 { font-size: var(--fs-h1); font-weight: 800; letter-spacing: 0.01em; }
h2 { font-size: var(--fs-h2); font-weight: 700; }
h3 { font-size: var(--fs-h3); font-weight: 700; }
.text-muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; }

/* ============================ 4. アイコン ================================= */
/* インラインSVGスプライト（#i-xxx）を currentColor で描画。外部ライブラリ不使用。 */
.icon {
    width: 1.15em; height: 1.15em;
    fill: none; stroke: currentColor;
    stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
    flex: none; vertical-align: -0.18em;
}
.icon-lg { width: 1.4em; height: 1.4em; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ============================ 5. ボタン ================================== */
/* 全ボタン共通。丸み/影/ホバー/押下/フォーカス/無効を統一。
   状態は色だけでなく、影・移動量・下線・アイコンでも区別する。 */
.btn {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 15px;
    font-size: var(--fs-btn); font-weight: 600; line-height: 1;
    color: var(--btn-fg);
    background: var(--btn-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--r-pill);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: transform var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease),
                background-color var(--dur) var(--ease),
                border-color var(--dur) var(--ease);
}
.btn:hover { transform: translateY(-1.5px); box-shadow: var(--shadow); background: var(--surface-2); }
.btn:active { transform: translateY(0) scale(0.98); box-shadow: var(--shadow-sm); }
/* フォーカスはキーボード操作時のみ明確なリングを表示 */
.btn:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}
.btn:disabled, .btn[disabled] {
    cursor: not-allowed; opacity: 0.5; filter: grayscale(0.3);
    box-shadow: none; transform: none;
}

/* 主要ボタン（ブランドピンク） */
.btn-primary {
    --btn-bg: linear-gradient(180deg, var(--pink-400), var(--pink-500));
    --btn-fg: var(--text-onbrand);
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(245, 106, 164, 0.35);
}
.btn-primary:hover { --btn-bg: linear-gradient(180deg, var(--pink-500), var(--pink-600)); background: var(--pink-500); }

/* 危険/成功（意味色 + アイコン併用で色以外にも識別可能に） */
.btn-danger  { --btn-bg: var(--danger-soft);  --btn-fg: var(--danger);  border-color: transparent; }
.btn-danger:hover  { --btn-bg: var(--danger);  --btn-fg: #fff; }
.btn-success { --btn-bg: var(--success-soft); --btn-fg: var(--success); border-color: transparent; }
.btn-success:hover { --btn-bg: var(--success); --btn-fg: #fff; }

/* 枠のみ/文字ボタン */
.btn-ghost { --btn-bg: transparent; box-shadow: none; }
.btn-ghost:hover { --btn-bg: var(--surface-2); text-decoration: underline; text-underline-offset: 3px; }

/* サイズ違い */
.btn-block { width: 100%; }
.btn-icon  { padding: 9px 14px; }
.btn-mini  { padding: 6px 11px; font-size: var(--fs-mini); gap: 5px; }

/* アイコンのみのボタン（正方形・ツールチップ付き想定） */
.btn-square { padding: 8px; border-radius: var(--r-sm); }

/* ============================ 6. フォーム ================================ */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: var(--fs-label); font-weight: 600; color: var(--text-muted); }

/* 入力欄・セレクト・テキストエリア共通 */
.field-input,
.search-input,
.sort-select {
    width: 100%;
    padding: 9px 12px;
    font-size: var(--fs-body);
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border-2);
    border-radius: var(--r-sm);
    outline: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field-input::placeholder, .search-input::placeholder { color: var(--text-muted); opacity: 0.8; }
.field-input:hover, .search-input:hover, .sort-select:hover { border-color: var(--pink-300); }
.field-input:focus-visible,
.search-input:focus-visible,
.sort-select:focus-visible,
.field-input:focus,
.search-input:focus,
.sort-select:focus {
    border-color: var(--pink-400);
    box-shadow: 0 0 0 3px var(--pastel-pink);
}
/* 入力エラー状態（色＋アイコン領域＋メッセージで示す） */
.field-input.is-error, .field.is-error .field-input {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}
.field-error {
    display: flex; align-items: center; gap: 6px;
    font-size: var(--fs-mini); color: var(--danger); font-weight: 600;
}

/* カラーピッカー */
.field-color {
    width: 100%; height: 40px; padding: 3px;
    border: 1.5px solid var(--border-2); border-radius: var(--r-sm);
    background: var(--surface); cursor: pointer;
}

/* カスタム チェックボックス / ラジオ（アクセントカラー統一） */
input[type="checkbox"], input[type="radio"] {
    appearance: none; -webkit-appearance: none;
    width: 18px; height: 18px; margin: 0;
    border: 1.5px solid var(--border-2); background: var(--surface);
    display: inline-grid; place-content: center; cursor: pointer;
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
input[type="checkbox"] { border-radius: 6px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]::before {
    content: ""; width: 10px; height: 10px; transform: scale(0);
    transition: transform var(--dur) var(--ease-pop);
    /* チェックマーク（マスク不要のクリップパス） */
    clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 16%, 82% 0, 39% 62%);
    background: #fff;
}
input[type="radio"]::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; transform: scale(0);
    transition: transform var(--dur) var(--ease-pop);
}
input[type="checkbox"]:checked, input[type="radio"]:checked { background: var(--brand); border-color: var(--brand); }
input[type="checkbox"]:checked::before, input[type="radio"]:checked::before { transform: scale(1); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
    outline: 3px solid var(--focus-ring); outline-offset: 2px;
}

/* チェック/ラジオを含むラベル行 */
.check-row { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-body); }

/* 検索ボックス（アイコン内包） */
.search-box { position: relative; display: flex; align-items: center; }
.search-box .search-icon {
    position: absolute; left: 11px; color: var(--text-muted); pointer-events: none;
}
.search-input { padding-left: 36px; }

/* ============================ 7. カード ================================= */
.card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

/* すりガラス面（ツールバー等）。クラス名は既存互換のため .glass を維持。 */
.glass {
    background: var(--frost);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow);
}

/* ============================ 8. トースト ================================ */
.toast {
    position: fixed; bottom: 28px; left: 50%;
    transform: translateX(-50%) translateY(16px);
    display: flex; align-items: center; gap: 8px;
    padding: 12px 20px; border-radius: var(--r-pill);
    background: var(--surface); color: var(--text);
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-body); font-weight: 600;
    opacity: 0; transition: opacity var(--dur-lg) var(--ease), transform var(--dur-lg) var(--ease);
    pointer-events: none; z-index: 3000;
    border-left: 5px solid var(--success);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { border-left-color: var(--danger); }

/* ============================ 9. ユーティリティ =========================== */
.spacer { flex: 1; }
.empty-hint { font-size: var(--fs-label); color: var(--text-muted); text-align: center; padding: 22px 8px; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 既定のフォーカス可視化（キーボード操作時） */
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
a:focus-visible { border-radius: 4px; }

/* スクロールバー装飾 */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--pink-200); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--pink-300); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* 動きを抑える設定を尊重（アクセシビリティ） */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
