/* ============================================
   AFS - 勤怠ファイリングシステム スタイル
   サイドバー型レイアウト
   ============================================ */

:root {
    --sidebar-width: 240px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255,255,255,0.7);
    --sidebar-text-dim: rgba(255,255,255,0.4);
    --sidebar-border: rgba(255,255,255,0.1);
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --bg: #f8fafc;
    --white: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

/* テーマ: ターコイズ × 紺 */
[data-theme="turquoise-navy"] {
    --accent: #14b8a6;
    --accent-hover: #0d9488;
    --sidebar-active: #14b8a6;
}

/* テーマ: レッド × 紺 */
[data-theme="red-navy"] {
    --accent: #e94560;
    --accent-hover: #d63d56;
    --sidebar-active: #e94560;
}

/* テーマ: グリーン × 紺 */
[data-theme="green-navy"] {
    --accent: #16a34a;
    --accent-hover: #15803d;
    --sidebar-active: #16a34a;
}

/* テーマ: パープル × 紺 */
[data-theme="purple-navy"] {
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --sidebar-active: #8b5cf6;
}

/* テーマ: ブルー × ライトグレー */
[data-theme="blue-gray"] {
    --sidebar-bg: #f3f4f6;
    --sidebar-hover: #e5e7eb;
    --sidebar-active: #2563eb;
    --sidebar-text: #1f2937;
    --sidebar-text-muted: rgba(31,41,55,0.7);
    --sidebar-text-dim: rgba(31,41,55,0.5);
    --sidebar-border: rgba(0,0,0,0.1);
}

/* テーマ: ターコイズ × ライトグレー */
[data-theme="turquoise-gray"] {
    --sidebar-bg: #f3f4f6;
    --sidebar-hover: #e5e7eb;
    --sidebar-active: #14b8a6;
    --sidebar-text: #1f2937;
    --sidebar-text-muted: rgba(31,41,55,0.7);
    --sidebar-text-dim: rgba(31,41,55,0.5);
    --sidebar-border: rgba(0,0,0,0.1);
    --accent: #14b8a6;
    --accent-hover: #0d9488;
}

/* テーマ: レッド × ライトグレー */
[data-theme="red-gray"] {
    --sidebar-bg: #f3f4f6;
    --sidebar-hover: #e5e7eb;
    --sidebar-active: #e94560;
    --sidebar-text: #1f2937;
    --sidebar-text-muted: rgba(31,41,55,0.7);
    --sidebar-text-dim: rgba(31,41,55,0.5);
    --sidebar-border: rgba(0,0,0,0.1);
    --accent: #e94560;
    --accent-hover: #d63d56;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ============================================
   サイドバー
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-logo {
    padding: 24px;
    border-bottom: 1px solid var(--sidebar-border);
    text-align: center;
}

.sidebar-logo h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.sidebar-logo .app-subtitle {
    font-size: 11px;
    color: var(--sidebar-text-dim);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-text-dim);
    padding: 12px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: 8px;
    margin: 2px 0;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--sidebar-border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    color: var(--sidebar-text-muted);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

.user-name {
    font-size: 14px;
    color: var(--sidebar-text);
}

.user-role {
    font-size: 11px;
    color: var(--sidebar-text-dim);
}

.logout-btn {
    display: block;
    text-align: center;
    padding: 10px;
    margin-top: 12px;
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.15);
    color: var(--sidebar-text);
}

/* ============================================
   メインコンテンツ
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 24px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 600;
}

.page-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ============================================
   カード
   ============================================ */
.card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ============================================
   ボタン
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* ============================================
   フォーム
   ============================================ */
.form-group {
    margin-bottom: 12px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-group .required {
    color: var(--danger);
}

.form-control {
    width: 100%;
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-select {
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--white);
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 20px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.form-section-title:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.form-actions {
    display: flex;
    gap: 12px;
    padding-top: 16px;
    margin-top: 16px;
    border-top: 1px solid var(--border);
}

/* ============================================
   テーブル
   ============================================ */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #f8fafc;
}

.table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table .amount {
    font-weight: 600;
    font-family: 'Consolas', monospace;
}

/* ============================================
   検索フィルター
   ============================================ */
.search-filters {
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.filter-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-input {
    padding: 8px 14px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    min-width: 150px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-filter {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    background: var(--text);
    color: var(--white);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-filter:hover {
    background: #374151;
}

.btn-filter-clear {
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    background: var(--white);
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-filter-clear:hover {
    background: var(--bg);
}

/* ============================================
   月ナビゲーション（BFSスタイル）
   ============================================ */
.toolbar-row {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.month-tabs-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.tab-nav-btn {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-light);
    transition: all 0.2s;
}

.tab-nav-btn:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
}

.tab-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.month-tabs {
    display: flex;
    flex-direction: row-reverse;
    gap: 12px;
    overflow: hidden;
    justify-content: center;
}

.month-tab {
    padding: 6px 16px;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.2s;
}

.month-tab:hover {
    background: var(--bg);
}

.month-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.month-tab-hidden {
    display: none;
}

.loading-text {
    color: var(--text-light);
    font-size: 14px;
    padding: 6px 16px;
}

/* ============================================
   リストヘッダー
   ============================================ */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--white);
}

.record-count {
    font-size: 13px;
    color: var(--text-light);
}

.export-buttons {
    display: flex;
    gap: 8px;
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 400;
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--bg);
    border-color: var(--accent);
    color: var(--accent);
}

/* ============================================
   リストテーブル
   ============================================ */
.table-wrapper {
    overflow-x: auto;
}

.list-table-container {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.list-table {
    width: 100%;
    border-collapse: collapse;
}

.list-table th {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-align: left;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.list-table td {
    padding: 8px 12px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.list-table tbody tr:hover {
    background: #f8fafc;
}

.list-table tbody tr:last-child td {
    border-bottom: none;
}

.td-date {
    font-weight: 500;
    color: var(--text);
}

.edit-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--text-light);
    border-radius: 6px;
    transition: all 0.2s;
}

.edit-icon:hover {
    background: #f1f5f9;
    color: var(--accent);
}

.empty-message {
    text-align: center;
    padding: 60px 20px !important;
    color: var(--text-light);
}

/* ============================================
   ステータスバッジ
   ============================================ */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 20px;
}

.status-badge.active,
.status-badge.confirmed {
    background: #dcfce7;
    color: #166534;
}

.status-badge.inactive,
.status-badge.draft {
    background: #f1f5f9;
    color: #475569;
}

.status-normal {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-holiday {
    background: #f3f4f6;
    color: #6b7280;
}

.status-holiday_work {
    background: #fef3c7;
    color: #d97706;
}

.status-paid_leave {
    background: #d1fae5;
    color: #059669;
}

.status-absent {
    background: #fee2e2;
    color: #dc2626;
}

/* ============================================
   右クリックメニュー
   ============================================ */
.context-menu {
    position: absolute;
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 140px;
    z-index: 1000;
    display: none;
    overflow: hidden;
}

.context-menu.show {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--bg);
}

.context-menu-item svg {
    flex-shrink: 0;
}

.context-menu-danger {
    color: var(--danger);
}

.context-menu-danger:hover {
    background: #fef2f2;
}

/* 選択行ハイライト */
.list-table tbody tr.selected {
    background: #dbeafe !important;
}

/* ============================================
   サマリーグリッド
   ============================================ */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.summary-item {
    background: var(--white);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.summary-item .summary-label {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.summary-item .summary-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

/* ============================================
   計算結果表示
   ============================================ */
.calc-result {
    background: var(--bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.calc-row:last-child {
    border-bottom: none;
}

.calc-row span {
    color: var(--text-light);
}

.calc-row strong {
    color: var(--text);
    font-size: 16px;
}

/* ============================================
   モーダル
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 16px 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ============================================
   ローディング
   ============================================ */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   成功モーダル（打刻システムと統一）
   ============================================ */
.success-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.success-modal-overlay.show {
    display: flex;
}

.success-modal-card {
    background: white;
    border-radius: 20px;
    padding: 40px 50px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 280px;
}

.success-icon-wrapper {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    position: relative;
}

.success-spinner {
    display: block;
    width: 80px;
    height: 80px;
    border: 5px solid #e0e0e0;
    border-top-color: var(--accent, #2563eb);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
    top: 0;
    left: 0;
}

.success-check {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--accent, #2563eb) 0%, var(--accent-hover, #1d4ed8) 100%);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    animation: scaleIn 0.3s ease-out;
}

.success-check.show {
    display: flex;
}

@keyframes scaleIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.success-text {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

/* ============================================
   アラート
   ============================================ */
.flash-messages {
    margin-bottom: 20px;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* ============================================
   ログインページ
   ============================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--white);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 3px;
}

.login-logo p {
    color: var(--text-light);
    margin-top: 8px;
}

.login-box .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    margin-top: 8px;
}

/* ============================================
   給与サマリー
   ============================================ */
.salary-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--white);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.summary-label {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.summary-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

/* ============================================
   設定ページ
   ============================================ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: #f8fafc;
}

.list-item-sub {
    font-size: 13px;
    color: var(--text-light);
}

/* ============================================
   エラーページ
   ============================================ */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.error-content {
    text-align: center;
}

.error-content h1 {
    font-size: 48px;
    color: var(--danger);
    margin-bottom: 16px;
}

.error-content p {
    color: var(--text-light);
    margin-bottom: 24px;
}

/* ============================================
   レスポンシブ
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
    }

    .form-row {
        flex-direction: column;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .salary-summary {
        grid-template-columns: 1fr;
    }

    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-input {
        width: 100%;
    }

    .month-nav {
        flex-wrap: wrap;
    }

    .summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
