/* --- ページ全体の基本設定 --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
    color: #333;
}

h1, h2, h3 {
    color: #a22041;
}

input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="date"], input[type="color"], button, textarea, select {
    font-size: 16px;
    padding: 10px;
    margin: 5px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
    font-family: inherit;
}

button {
    cursor: pointer;
    background-color: #a22041;
    color: white;
    border: none;
}

button:hover {
    background-color: #821a34;
}

hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 20px 0;
}

/* --- ローディング画面用スタイル --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.spinner {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #a22041;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* --- ログイン画面用スタイル --- */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#login-form-container {
    background-color: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 350px;
}

#login-form-container h2 {
    text-align: center;
    margin-top: 0;
    color: #333;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --- レイアウト用スタイル --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

#sidebar {
    width: 240px;
    background-color: #f4f4f4;
    padding: 20px;
    border-right: 1px solid #ddd;
    flex-shrink: 0;
    box-sizing: border-box;
    transition: transform 0.3s ease-in-out;
}

#sidebar h2 {
    margin-top: 0;
}

#sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sidebar ul li a {
    display: block;
    padding: 10px 15px;
    color: #333;
    text-decoration: none;
    border-radius: 5px;
}

#sidebar ul li a:hover {
    background-color: #e9e9e9;
}

#sidebar ul li a.active {
    background-color: #dcdcdc;
    font-weight: bold;
}

.submenu {
    display: none;
    list-style: none;
    padding-left: 15px;
    margin-top: 5px;
}

.submenu li a {
    padding-left: 20px;
    font-size: 0.95em;
}

.submenu li a.active {
    background-color: #e0e0e0;
}

#main-content {
    flex-grow: 1;
    padding: 20px 40px;
    overflow-y: auto;
    min-width: 0;
    box-sizing: border-box;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#start-task-button {
    margin: 0;
}

#timerDisplay {
    margin-top: 0;
}

#recordList {
    list-style: none;
    padding: 0;
}

#recordList li {
    background-color: white;
    padding: 15px;
    border-bottom: 1px solid #eee;
}

#recordList li:first-child {
    border-top: 1px solid #eee;
}

/* --- モバイル用ヘッダー --- */
#mobile-header {
    display: none;
}

#sidebar-toggle-button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

#app-title {
    margin: 0;
    font-size: 1.2rem;
}

#overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* --- SweetAlert2ポップアップ内のカスタムスタイル --- */
.swal2-html-container {
    overflow: visible !important;
}

.custom-swal-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    text-align: left;
}

.custom-swal-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.custom-swal-form label {
    font-weight: bold;
    font-size: 0.9em;
}

.custom-swal-form input,
.custom-swal-form select,
.custom-swal-form textarea {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 10px;
    font-size: 1em;
}

.time-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.time-group input {
    flex: 1;
}

.time-group span {
    font-weight: bold;
}

/* --- ダッシュボード用スタイル --- */
.date-filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.date-filter-form input[type="date"],
.date-filter-form select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    margin: 0;
}

.date-filter-form button {
    margin: 0;
}

.preset-buttons {
    display: flex;
    gap: 10px;
}

.preset-btn {
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #ccc;
    font-size: 14px;
    padding: 8px 12px;
}

.preset-btn:hover {
    background-color: #e0e0e0;
}


.dashboard-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}
.summary-item {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.summary-label {
    display: block;
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
}
.summary-value {
    display: block;
    font-size: 28px;
    font-weight: bold;
    color: #a22041;
}

/* --- 管理者ページ用スタイル --- */
.admin-section {
    margin-top: 20px;
}

.admin-section h2 {
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #eee;
}

#add-department-form, #add-rate-form, #add-user-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#add-department-form input, #add-rate-form input, #add-user-form input, #add-rate-form select, #add-user-form select {
    margin: 0;
}

#departments-table,
#users-table,
#rates-table,
#activity-log-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#departments-table th,
#departments-table td,
#users-table th,
#users-table td,
#rates-table th,
#rates-table td,
#activity-log-table th,
#activity-log-table td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
    vertical-align: middle;
}

#departments-table th,
#users-table th,
#rates-table th,
#activity-log-table th {
    background-color: #f8f8f8;
}

#departments-table button,
#users-table button,
#rates-table button {
    margin-right: 5px;
    padding: 5px 10px;
    font-size: 14px;
}

/* --- リアルタイム稼働状況のスタイル --- */
#real-time-status-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
}

.status-card {
    background-color: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-left: 5px solid #2ecc71;
}

.status-card .user-name {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.status-card .task-title {
    font-size: 1em;
    color: #555;
    margin: 5px 0;
}

.status-card .elapsed-time {
    font-size: 1.2em;
    font-weight: bold;
    color: #a22041;
    text-align: right;
}

/* --- プロフィールページ用スタイル --- */
#profile-update-form,
#password-update-form {
    max-width: 500px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#profile-view .form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

#profile-view .form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

#profile-view .form-group input {
    width: 100%;
    margin: 0;
}

#profile-view button {
    margin-top: 10px;
    width: auto;
    padding: 10px 20px;
}

.swal2-popup {
    width: 90% !important;
}

/* --- レスポンシブ対応 --- */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 80%;
        max-width: 280px;
        height: 100%;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
        border-right: none;
        box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    }
    #sidebar.active {
        left: 0;
    }

    #overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.4);
        z-index: 999;
        display: none;
    }
    #overlay.active {
        display: block;
    }

    #main-content {
        padding: 10px;
    }

    #mobile-header {
        display: flex;
        align-items: center;
        background-color: #a22041;
        color: white;
        padding: 10px;
    }

    .main-header {
        display: none;
    }

    .dashboard-summary {
        grid-template-columns: 1fr;
    }

    .date-filter-form {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-controls, .preset-buttons {
        width: 100%;
        justify-content: space-around;
    }

    .chart-container {
        width: 100% !important;
        height: 50vh !important;
    }

    .admin-section {
        overflow-x: auto;
    }
    
    #departments-table,
    #users-table,
    #rates-table,
    #activity-log-table {
        white-space: nowrap;
    }

    .swal2-popup {
        width: 90% !important;
    }

    .time-group {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
}

@media (min-width: 1025px) {
    .app-container {
        flex-direction: row;
    }
    #sidebar {
        position: static;
        left: 0;
        height: auto;
        box-shadow: none;
    }
    #mobile-header {
        display: none;
    }
    .main-header {
        display: flex;
    }
    #overlay {
        display: none !important;
    }
}