/* ===========================
   Zumen Reading System v2.0
   Modern, Bright, Beautiful UI
   =========================== */

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ===== Variables ===== */
:root {
    /* Brand colors */
    --brand-primary: #4F46E5;        /* Indigo 600 - メインアクセント */
    --brand-primary-hover: #4338CA;
    --brand-primary-light: #EEF2FF;
    --brand-accent: #F59E0B;          /* Amber 500 - サブアクセント */
    --brand-success: #10B981;         /* Emerald 500 */
    --brand-warning: #F59E0B;
    --brand-danger: #EF4444;
    --brand-info: #3B82F6;

    /* Neutral colors - 明るくモダン */
    --bg-app: #FAFBFD;                /* アプリ全体の背景（ほんのり青み） */
    --bg-card: #FFFFFF;
    --bg-elevated: #FFFFFF;
    --bg-muted: #F3F4F6;
    --bg-hover: #F9FAFB;
    --bg-pressed: #F3F4F6;

    /* Text colors */
    --text-primary: #111827;          /* Gray 900 */
    --text-secondary: #4B5563;        /* Gray 600 */
    --text-tertiary: #9CA3AF;         /* Gray 400 */
    --text-on-brand: #FFFFFF;
    --text-link: var(--brand-primary);

    /* Border colors */
    --border-light: #F3F4F6;
    --border-default: #E5E7EB;
    --border-strong: #D1D5DB;

    /* Shadows - 浮遊感 */
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.05), 0 1px 2px -1px rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.05);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --t-fast: 120ms cubic-bezier(0.16, 1, 0.3, 1);
    --t-base: 200ms cubic-bezier(0.16, 1, 0.3, 1);
    --t-slow: 300ms cubic-bezier(0.16, 1, 0.3, 1);

    /* Spacing scale (rem) */
    --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
    --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
    --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;
    --space-16: 4rem;   --space-20: 5rem;

    /* Sidebar width */
    --sidebar-w: 220px;
}

/* ===== Base ===== */
body {
    font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 
                 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
    font-feature-settings: "palt" 1, "kern" 1;
    color: var(--text-primary);
    background: var(--bg-app);
    font-size: 14px;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5 {
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text-primary);
}

h1 { font-size: 1.875rem; line-height: 1.2; }
h2 { font-size: 1.5rem; line-height: 1.25; }
h3 { font-size: 1.125rem; line-height: 1.3; }
h4 { font-size: 1rem; line-height: 1.4; }

.text-display {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    font-feature-settings: "tnum" 1, "lnum" 1;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.text-mono {
    font-family: 'JetBrains Mono', 'Menlo', monospace;
    font-feature-settings: "tnum" 1;
}

.text-muted { color: var(--text-secondary); }
.text-subtle { color: var(--text-tertiary); }
.text-brand { color: var(--brand-primary); }
.text-success { color: var(--brand-success); }
.text-warning { color: var(--brand-warning); }
.text-danger { color: var(--brand-danger); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-4);
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--t-fast);
    white-space: nowrap;
    user-select: none;
}

.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--brand-primary);
    color: var(--text-on-brand);
    box-shadow: 0 1px 2px 0 rgb(79 70 229 / 0.2);
}
.btn-primary:hover {
    background: var(--brand-primary-hover);
    box-shadow: 0 4px 12px -2px rgb(79 70 229 / 0.4);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--brand-danger);
    color: var(--text-on-brand);
}
.btn-danger:hover { background: #DC2626; }

.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: 13px; }
.btn-lg { height: 48px; padding: 0 var(--space-6); font-size: 15px; }
.btn-block { width: 100%; }

.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

/* ===== Input ===== */
.input, .select, .textarea {
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    transition: all var(--t-fast);
    box-sizing: border-box;
}

.input:hover, .select:hover {
    border-color: var(--border-strong);
}

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgb(79 70 229 / 0.1);
}

.textarea {
    height: auto;
    min-height: 96px;
    padding: var(--space-3);
    line-height: 1.6;
    resize: vertical;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.input-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-label .required {
    color: var(--brand-danger);
    margin-left: 2px;
}

.input-help {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ===== Card ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    transition: all var(--t-base);
}

.card-hoverable:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-padded { padding: var(--space-6); }
.card-padded-sm { padding: var(--space-4); }

/* ===== Stat Card - ダッシュボード用 ===== */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-6);
    transition: all var(--t-base);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent-color, var(--brand-primary));
    opacity: 0;
    transition: opacity var(--t-base);
}
.stat-card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.stat-card:hover::before { opacity: 1; }

.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-3);
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
}

.stat-unit {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-tertiary);
}

.stat-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.stat-card[data-accent="indigo"] { --accent-color: #4F46E5; }
.stat-card[data-accent="emerald"] { --accent-color: #10B981; }
.stat-card[data-accent="amber"] { --accent-color: #F59E0B; }
.stat-card[data-accent="rose"] { --accent-color: #F43F5E; }
.stat-card[data-accent="sky"] { --accent-color: #0EA5E9; }
.stat-card[data-accent="violet"] { --accent-color: #8B5CF6; }

/* ===== Badge ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-secondary);
    line-height: 1.4;
}

.badge-success { background: #D1FAE5; color: #065F46; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger  { background: #FEE2E2; color: #991B1B; }
.badge-info    { background: #DBEAFE; color: #1E40AF; }
.badge-brand   { background: var(--brand-primary-light); color: var(--brand-primary); }

/* ===== Alert ===== */
.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-md);
    border: 1px solid;
    font-size: 13px;
    line-height: 1.6;
}

.alert-info {
    background: #EFF6FF;
    border-color: #BFDBFE;
    color: #1E3A8A;
}

.alert-warning {
    background: #FFFBEB;
    border-color: #FDE68A;
    color: #78350F;
}

.alert-danger {
    background: #FEF2F2;
    border-color: #FECACA;
    color: #7F1D1D;
}

.alert-success {
    background: #ECFDF5;
    border-color: #A7F3D0;
    color: #064E3B;
}

/* ===== Table ===== */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-muted);
    border-bottom: 1px solid var(--border-default);
}

.table tbody td {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    font-weight: 500;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr {
    transition: background var(--t-fast);
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

.table-clickable tbody tr {
    cursor: pointer;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 280px;
    max-width: 420px;
    animation: slideIn 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast::before {
    content: '';
    width: 4px;
    height: 24px;
    border-radius: 2px;
    background: var(--brand-info);
    flex-shrink: 0;
}

.toast.toast-success::before { background: var(--brand-success); }
.toast.toast-warning::before { background: var(--brand-warning); }
.toast.toast-danger::before { background: var(--brand-danger); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(17 24 39 / 0.5);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 200ms;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 540px;
    width: 90vw;
    max-height: 85vh;
    overflow: auto;
    animation: scaleIn 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body { padding: var(--space-6); }

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

/* ===== Utility ===== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }
.grid { display: grid; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 24px; }
.text-3xl { font-size: 30px; }
.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }
.hidden { display: none !important; }
.relative { position: relative; }
.absolute { position: absolute; }
.cursor-pointer { cursor: pointer; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); } .mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); } .mb-8 { margin-bottom: var(--space-8); }
.p-4 { padding: var(--space-4); } .p-6 { padding: var(--space-6); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); } .px-4 { padding-left: var(--space-4); padding-right: var(--space-4); } .px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); } .py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); } .py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* グリッド */
.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1024px) {
    .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: 1fr; }
}

/* スクロールバー */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ===== v2.6 追加調整（安全版） ===== */

/* ボタンのhover感を統一 */
.btn { white-space: nowrap; }

/* マスタータブの hover */
.master-tab-btn { transition: background var(--t-fast); }
.master-tab-btn:hover { background: var(--bg-hover); }

/* x-cloak でちらつき防止 */
[x-cloak] { display: none !important; }

/* 入力欄の数値右寄せ用ヘルパー */
.text-right input.input,
.text-right input.sheet-cell-input { text-align: right; }

/* マスタタブのテーブル：列幅指定を尊重させる */
.table {
    table-layout: fixed;
    width: 100%;
}
/* テーブルセル内の input がはみ出さないように */
.table td input.input,
.table td .select,
.table td input[type="text"],
.table td input[type="number"] {
    font-size: 13px;
    min-width: 0;
    max-width: 100%;
}
/* テーブルセルのテキストオーバーフロー */
.table td {
    overflow: hidden;
    vertical-align: middle;
}
