/* rank-tracker 共通スタイル */

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-text: #1f2937;
    --color-bg: #f3f4f6;
    --color-border: #d1d5db;
    --color-error-bg: #fef2f2;
    --color-error-text: #b91c1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    color: var(--color-text);
    background-color: var(--color-bg);
}

/* --- ログイン画面 --- */
.login-container {
    max-width: 360px;
    margin: 10vh auto 0;
    padding: 2rem;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.login-title {
    margin: 0 0 1.5rem;
    text-align: center;
    font-size: 1.5rem;
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.login-form input {
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

/* --- 共通部品 --- */
.alert {
    padding: 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.alert-error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
}

.alert-success {
    background-color: #f0fdf4;
    color: #15803d;
}

.error-list {
    margin: 0;
    padding-left: 1.25rem;
}

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

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

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

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

/* --- アプリ共通レイアウト --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--color-border);
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.app-name {
    font-weight: bold;
}

.app-nav {
    display: flex;
    gap: 1rem;
}

.app-nav a {
    color: var(--color-text);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9375rem;
}

.app-nav a:hover {
    background-color: var(--color-bg);
}

.app-nav a.active {
    color: var(--color-primary);
    font-weight: bold;
}

.container {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

.container-narrow {
    max-width: 640px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- テーブル --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--color-border);
    font-size: 0.9375rem;
}

.data-table th,
.data-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

.data-table thead th {
    background-color: #f9fafb;
    font-size: 0.8125rem;
}

.row-inactive {
    color: #9ca3af;
    background-color: #fafafa;
}

.actions {
    white-space: nowrap;
}

.inline-form {
    display: inline-block;
    margin-left: 0.25rem;
}

/* --- バッジ --- */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
}

.badge-active {
    background-color: #dcfce7;
    color: #15803d;
}

.badge-inactive {
    background-color: #e5e7eb;
    color: #4b5563;
}

/* --- フォーム(登録・編集) --- */
.edit-form {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5rem;
}

.edit-form .form-group {
    margin-bottom: 1.25rem;
}

.edit-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: bold;
}

.edit-form input[type="text"],
.edit-form select,
.edit-form textarea {
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.edit-form .checkbox-label {
    font-weight: normal;
}

.form-help {
    margin: 0.25rem 0 0;
    font-size: 0.8125rem;
    color: #6b7280;
}

.required {
    color: var(--color-error-text);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.btn-inline {
    width: auto;
}

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
}

a.btn {
    text-decoration: none;
    text-align: center;
}

/* --- キーワード管理 --- */
.breadcrumb {
    font-size: 0.875rem;
    color: #6b7280;
}

.breadcrumb a {
    color: var(--color-primary);
}

.keyword-count {
    font-size: 0.9375rem;
}

.keyword-add {
    margin-bottom: 1.5rem;
}

.keyword-add-form {
    display: flex;
    gap: 0.5rem;
}

.keyword-add-form input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.input-order {
    width: 4.5rem;
    padding: 0.375rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.input-phrase {
    width: 100%;
    padding: 0.375rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

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

/* --- 計測ログ(S-05) --- */
.summary-box {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.summary-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.summary-counts {
    margin: 0;
    font-size: 0.9375rem;
}

.summary-done {
    color: #15803d;
    font-weight: bold;
}

.summary-pending {
    color: #6b7280;
    font-weight: bold;
}

.summary-failed {
    color: var(--color-error-text);
    font-weight: bold;
}

.badge-status-failed {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
}

.error-detail {
    max-width: 320px;
    font-size: 0.8125rem;
    word-break: break-all;
}

/* ===== S-02 ダッシュボード ===== */

.dashboard {
    display: flex;
    gap: 1.5rem;
    max-width: 1280px;
    margin: 1.5rem auto;
    padding: 0 1rem;
    align-items: flex-start;
}

.site-sidebar {
    flex: 0 0 220px;
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem;
}

.site-sidebar input[type="search"] {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.875rem;
    box-sizing: border-box;
}

#site-list {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
    max-height: 70vh;
    overflow-y: auto;
}

#site-list li a {
    display: block;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    color: #374151;
    text-decoration: none;
    font-size: 0.9375rem;
    word-break: break-all;
}

#site-list li a:hover {
    background-color: #f3f4f6;
}

#site-list li a.selected {
    background-color: #2563eb;
    color: #fff;
}

#site-list li.site-inactive a {
    color: #9ca3af;
}

.dashboard-main {
    flex: 1;
    min-width: 0;
}

.dashboard-main .site-url {
    color: #6b7280;
    font-size: 0.875rem;
}

.keyword-rank-table tbody tr {
    cursor: pointer;
}

.keyword-rank-table tbody tr:hover {
    background-color: #f3f4f6;
}

.keyword-rank-table tbody tr.selected {
    background-color: #dbeafe;
}

.data-table td.num {
    text-align: right;
    white-space: nowrap;
}

.dod-up {
    color: #2563eb;
    font-weight: bold;
}

.dod-down {
    color: #dc2626;
    font-weight: bold;
}

.dod-flat {
    color: #9ca3af;
}

.found-url {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    color: #6b7280;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 2rem;
}

.period-switch button {
    padding: 0.3rem 0.8rem;
    border: 1px solid #d1d5db;
    background-color: #fff;
    cursor: pointer;
    font-size: 0.875rem;
}

.period-switch button:first-child {
    border-radius: 4px 0 0 4px;
}

.period-switch button:last-child {
    border-radius: 0 4px 4px 0;
}

.period-switch button + button {
    border-left: none;
}

.period-switch button.active {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.chart-container {
    position: relative;
    height: 360px;
    background-color: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 1.5rem;
}

.csv-form {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    color: #374151;
}

.csv-form input[type="date"] {
    padding: 0.25rem 0.4rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.875rem;
}

/* ===== S-06 設定 ===== */

.settings-table th {
    width: 280px;
    text-align: left;
    vertical-align: top;
    background-color: #f9fafb;
}

.settings-table .form-help {
    display: block;
    margin-top: 0.3rem;
}
