/* ==========================================
   経費精算システム (Keihi) - メインスタイル
   ========================================== */

:root {
    /* カラーパレット */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;

    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;

    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* レイアウト */
    --sidebar-width: 260px;
    --topbar-height: 60px;

    /* フォント */
    --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;

    /* シャドウ */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

    /* 角丸 */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* トランジション */
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ==========================================
   ログインページ
   ========================================== */

.login-body {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-logo {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    color: #fff;
    font-size: 32px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 24px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-google:hover {
    background: var(--bg);
    border-color: var(--text-secondary);
    text-decoration: none;
}

/* ==========================================
   アプリレイアウト
   ========================================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* サイドバー */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo-icon {
    font-size: 24px;
    color: var(--sidebar-active);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 16px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 14px;
    transition: var(--transition);
    text-decoration: none;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.nav-item.nav-active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--sidebar-active);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.sidebar-avatar-placeholder {
    background: var(--sidebar-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-text);
    font-size: 14px;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.nav-logout {
    color: var(--danger) !important;
}

.nav-logout:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

/* メインエリア */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
}

.sidebar-overlay {
    display: none;
}

.main-content {
    flex: 1;
    padding: 24px;
}

/* ==========================================
   カード
   ========================================== */

.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.card-body {
    padding: 20px;
}

/* ==========================================
   統計カード（ダッシュボード）
   ========================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.stat-icon-blue {
    background: #dbeafe;
    color: #2563eb;
}

.stat-icon-green {
    background: #d1fae5;
    color: #10b981;
}

.stat-icon-yellow {
    background: #fef3c7;
    color: #f59e0b;
}

.stat-icon-red {
    background: #fce7f3;
    color: #ec4899;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

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

/* ==========================================
   テーブル
   ========================================== */

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th,
table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

table tr:hover td {
    background: rgba(59, 130, 246, 0.03);
}

table .text-right {
    text-align: right;
}

/* ==========================================
   バッジ（ステータス）
   ========================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}

.badge-blue {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-green {
    background: #d1fae5;
    color: #047857;
}

.badge-yellow {
    background: #fef3c7;
    color: #b45309;
}

.badge-red {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-gray {
    background: #f1f5f9;
    color: #475569;
}

/* ==========================================
   ボタン
   ========================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: var(--font-family);
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ==========================================
   フォーム
   ========================================== */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-label .required {
    color: var(--danger);
    margin-left: 4px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-family);
    transition: var(--transition);
    background: var(--surface);
    color: var(--text);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-inline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* ==========================================
   アラート
   ========================================== */

.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #d1fae5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
}

.alert-warning {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fcd34d;
}

.alert-info {
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
}

/* ==========================================
   空状態
   ========================================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
}

/* ==========================================
   明細テーブル（申請作成）
   ========================================== */

.detail-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr 120px 150px auto;
    gap: 8px;
    align-items: end;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.detail-row .form-group {
    margin-bottom: 0;
}

.add-detail-btn {
    margin-top: 12px;
}

/* ==========================================
   アクションバー
   ========================================== */

.page-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

/* ==========================================
   詳細ページ
   ========================================== */

.detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0;
}

.detail-grid dt {
    padding: 10px 16px;
    background: var(--bg);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.detail-grid dd {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

/* ==========================================
   左右分割レイアウト（詳細画面）
   ========================================== */
.detail-flex-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: nowrap;
    /* 強制的に並べる */
    width: 100%;
}

.detail-col-left,
.detail-col-right {
    flex: 1;
    /* 50/50 分割 */
    min-width: 0;
    /* 内容がはみ出ても縮小可能にする */
}

@media (max-width: 600px) {

    /* さすがに600px以下（スマホ縦向き程度）は使い勝手を考えて折り返す */
    .detail-flex-row {
        flex-wrap: wrap;
    }

    .detail-col-left,
    .detail-col-right {
        flex: 1 1 100%;
    }
}

/* 添付ファイル表示の強化 (変動式) */
.attachment-grid.large {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.attachment-grid.large .attachment-preview {
    height: auto;
    aspect-ratio: 4 / 3;
    max-height: 400px;
}

.attachment-grid.large .attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.attachment-grid.large .pdf-preview i,
.attachment-grid.large .file-preview i {
    font-size: 64px;
}

/* ==========================================
   モダールダイアログ
   ========================================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.active {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    margin: 20px;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ==========================================
   レスポンシブ
   ========================================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    .main-area {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .main-content {
        padding: 16px;
    }

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

    .detail-row {
        grid-template-columns: 1fr;
    }

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

    .detail-grid dt {
        border-bottom: none;
        padding-bottom: 4px;
    }

    .detail-grid dd {
        padding-top: 0;
    }

    .page-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-group {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 32px 24px;
    }

    .stat-value {
        font-size: 22px;
    }
}