/* ==========================================================================
   PTA旗振りシフト割り当てツール - スタイルシート
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Variables
   -------------------------------------------------------------------------- */
:root {
    /* Primary Colors - Deep Green Theme (matching manual.html) */
    --color-primary: #2e7d32;
    --color-primary-dark: #006837;
    --color-primary-light: #4caf50;
    --color-primary-subtle: #e8f5e9;

    /* Secondary & Accent */
    --color-secondary: #3b82f6;
    --color-accent: #f59e0b;
    --color-danger: #ef4444;

    /* Neutral */
    --color-bg: #f0fdf4;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-light: #64748b;
    --color-text-muted: #94a3b8;

    /* Status */
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-error: #ef4444;

    /* Typography */
    --font-main: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);

    /* Transitions */
    --transition: all 0.3s ease;
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
    color: white;
    padding: var(--space-xl) 0;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.logo {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

.tagline {
    opacity: 0.9;
    font-size: 0.95rem;
}

/* --------------------------------------------------------------------------
   Main Content
   -------------------------------------------------------------------------- */
.main {
    flex: 1;
    padding: var(--space-xl) var(--space-lg);
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-xl);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.card-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    flex: 1;
}

.card-body {
    padding: var(--space-lg);
}

.step-badge {
    background: var(--color-primary);
    color: white;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* --------------------------------------------------------------------------
   Upload Section
   -------------------------------------------------------------------------- */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.upload-box {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

.upload-box:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-subtle);
}

.upload-box.uploaded {
    border-color: var(--color-success);
    border-style: solid;
    background: #f0fdf4;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
}

.upload-box h3 {
    font-size: 1.1rem;
    margin-bottom: var(--space-xs);
}

.upload-box p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--space-md);
}

.file-status {
    margin-top: var(--space-md);
    font-size: 0.85rem;
    color: var(--color-success);
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 125, 50, 0.4);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-primary);
    color: white;
}

.btn-large {
    padding: var(--space-md) var(--space-2xl);
    font-size: 1.1rem;
}

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-lg);
    border-bottom: 2px solid var(--color-border);
    padding-bottom: var(--space-xs);
}

.tab {
    padding: var(--space-sm) var(--space-lg);
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text-light);
    cursor: pointer;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: var(--transition);
}

.tab:hover {
    color: var(--color-primary);
    background: var(--color-primary-subtle);
}

.tab.active {
    color: var(--color-primary);
    background: var(--color-primary-subtle);
    border-bottom: 2px solid var(--color-primary);
    margin-bottom: -2px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* --------------------------------------------------------------------------
   Stats Row
   -------------------------------------------------------------------------- */
.stats-row {
    display: flex;
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.stat-item {
    background: var(--color-primary-subtle);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.stat-item strong {
    color: var(--color-primary-dark);
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrapper {
    overflow: auto;
    max-height: 75vh;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    position: relative;
    /* Stickyのコンテキスト確保 */
}

table {
    width: 100%;
    border-collapse: separate;
    /* Stickyを確実に効かせるためseparateに変更 */
    border-spacing: 0;
    font-size: 0.85rem;
}

th,
td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    background-color: var(--color-surface);
    /* デフォルト背景色 */
}

/* === Sticky Header Configuration === */

/* 全ヘッダーセルの基本設定 */
thead th {
    position: sticky;
    background-color: #ecfdf5;
    /* Default header background */
    z-index: 20;
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
    /* separate時のボーダー補完 */
}

/* 1行目: 場所名など */
thead tr:nth-child(1) th {
    top: 0;
    height: 45px;
}

/* 2行目: 充足/総枠 */
thead tr:nth-child(2) th {
    top: 45px;
    height: 45px;
    background-color: #f8fafc;
    /* 行固有の色 */
}

/* 3行目: 未割り当て率 */
thead tr:nth-child(3) th {
    top: 90px;
    height: 45px;
    background-color: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
}

/* === Sticky Columns Configuration (Date & Day) === */

/* 1列目: 日付 */
tbody th:nth-child(1),
tbody td:nth-child(1),
thead tr:nth-child(1) th:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 10;
    min-width: 110px;
    max-width: 110px;
    border-right: 2px solid var(--color-border);
    /* 列の区切りを強調 */
    background-color: var(--color-surface);
}

/* 2列目: 曜日 */
tbody th:nth-child(2),
tbody td:nth-child(2),
thead tr:nth-child(1) th:nth-child(2) {
    position: sticky;
    left: 110px;
    /* 1列目の幅 */
    z-index: 10;
    min-width: 60px;
    max-width: 60px;
    border-right: 2px solid var(--color-border);
    background-color: var(--color-surface);
}

/* 1列目・2列目の結合ヘッダー（2行目・3行目の左端ラベル） */
thead tr:nth-child(2) th:first-child,
thead tr:nth-child(3) th:first-child {
    position: sticky;
    left: 0;
    z-index: 30;
    /* 最前面 */
    width: 170px;
    /* 1列目+2列目の幅 */
    min-width: 170px;
    border-right: 2px solid var(--color-border);
    background-color: #f8fafc;
    /* 行の色に合わせる */
}

/* 左上隅（1行目の左2列）の重なり順を最前面に */
thead tr:nth-child(1) th:nth-child(1),
thead tr:nth-child(1) th:nth-child(2) {
    z-index: 30;
    background-color: #ecfdf5;
}

/* 休日行の背景色対応 (td自体に色がついている場合は透過しないのでOKだが、念のため) */
tbody tr[style*="background"] td:nth-child(1),
tbody tr[style*="background"] td:nth-child(2) {
    background-color: inherit;
    /* 行の色を引き継ぐ */
}

tr:hover {
    background: #fafafa;
}

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

/* Cell highlighting for results */
.cell-assigned {
    background: #dcfce7;
    font-weight: 500;
}

.cell-empty {
    background: #fef2f2;
    color: var(--color-text-muted);
}

.cell-highlight {
    background: #fef3c7;
}

/* --------------------------------------------------------------------------
   Data Preview Table - Column Width Adjustments
   -------------------------------------------------------------------------- */
/* 姓と名の列幅を統一 */
.tab-content table th:nth-child(1),
.tab-content table td:nth-child(1),
.tab-content table th:nth-child(2),
.tab-content table td:nth-child(2) {
    min-width: 100px;
    max-width: 100px;
}


/* --------------------------------------------------------------------------
   Assignment Options
   -------------------------------------------------------------------------- */
.assign-options {
    margin-bottom: var(--space-xl);
}

.option-group {
    margin-bottom: var(--space-md);
}

.option-group label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-xs);
    color: var(--color-text);
}

.option-group select {
    width: 100%;
    max-width: 400px;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    background: white;
    cursor: pointer;
    transition: var(--transition);
}

.option-group select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.action-buttons {
    text-align: center;
}

/* --------------------------------------------------------------------------
   Progress Bar
   -------------------------------------------------------------------------- */
.progress-container {
    margin-top: var(--space-xl);
    text-align: center;
}

.progress-bar {
    height: 8px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--space-sm);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light));
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    color: var(--color-text-light);
    font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Result Summary
   -------------------------------------------------------------------------- */
.result-summary {
    display: block;
    /* Changed from grid to block to allow full-width flex rows */
    margin-bottom: 2rem;
}

.summary-card {
    background: var(--color-primary-subtle);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    text-align: center;
}

.summary-card.warning {
    background: #fef3c7;
}

.summary-card.danger {
    background: #fee2e2;
}

.summary-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary-dark);
}

.summary-card.warning .summary-number {
    color: var(--color-warning);
}

.summary-card.danger .summary-number {
    color: var(--color-danger);
}

.summary-label {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* --------------------------------------------------------------------------
   Unassigned Section
   -------------------------------------------------------------------------- */
.unassigned-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-sm);
}

.unassigned-item {
    background: #fef2f2;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border-left: 3px solid var(--color-danger);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
    text-align: center;
    color: white;
    padding: 24px 16px;
    font-size: 0.85rem;
    background: linear-gradient(135deg, #004d2a 0%, #006837 100%);
    width: 100%;
}

.footer p {
    margin: 0;
    color: white;
}

/* --------------------------------------------------------------------------
   Utility Classes
   -------------------------------------------------------------------------- */
.hidden {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .container {
        padding: 0 var(--space-md);
    }

    .card-header {
        flex-wrap: wrap;
    }

    .upload-grid {
        grid-template-columns: 1fr;
    }

    .stats-row {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .tabs {
        flex-wrap: wrap;
    }

    .btn-large {
        width: 100%;
    }
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.4s ease;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

.loading {
    animation: pulse 1.5s ease infinite;
}

/* --------------------------------------------------------------------------
   Modal Dialog
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 480px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: var(--space-lg);
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border-bottom: 1px solid var(--color-border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary-dark);
}

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

.modal-body label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-sm);
    color: var(--color-text);
}

.filename-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: var(--space-sm);
}

.filename-input {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--color-border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
}

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

.filename-extension {
    padding: var(--space-sm) var(--space-md);
    background: var(--color-primary-subtle);
    border: 2px solid var(--color-border);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--color-text-light);
    font-weight: 500;
    font-size: 0.95rem;
}

.filename-hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0;
}

.modal-footer {
    padding: var(--space-md) var(--space-lg);
    background: #f9fafb;
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}