/* =============================================================================
   dedi.galaxia.works - Galaxia Console v4
   企業向け SaaS テイスト: ホワイト基調 + ダークモード切替 + 装飾を抑制
   ============================================================================= */

/* ---------- Light theme (default) ---------- */
:root {
    --brand:           #2D6A4F;
    --brand-hover:     #1B4332;
    --brand-soft:      #E7F3EC;
    --brand-soft-hover:#D8ECDF;
    --brand-text-on:   #FFFFFF;

    /* surface (背景階層) */
    --bg-page:         #FFFFFF;
    --bg-sidebar:      #F8F9FA;
    --bg-card:         #FFFFFF;
    --bg-subtle:       #F5F7FA;
    --bg-input:        #FFFFFF;
    --bg-hover:        #F5F7FA;
    --bg-row-hover:    #FAFBFC;

    /* border */
    --border:          #E5E7EB;
    --border-strong:   #D1D5DB;
    --border-subtle:   #F1F3F5;
    --border-focus:    rgba(45, 106, 79, 0.25);

    /* text */
    --text:            #111827;
    --text-secondary:  #4B5563;
    --text-tertiary:   #6B7280;
    --text-muted:      #9CA3AF;

    /* semantic */
    --success:         #15803D;
    --success-bg:      #ECFDF5;
    --success-border:  #BBF7D0;
    --warn:            #B45309;
    --warn-bg:         #FEF3C7;
    --warn-border:     #FDE68A;
    --danger:          #B91C1C;
    --danger-bg:       #FEF2F2;
    --danger-border:   #FECACA;
    --info:            #1D4ED8;
    --info-bg:         #EFF6FF;
    --info-border:     #BFDBFE;

    /* shape */
    --radius-sm:       4px;
    --radius-md:       6px;
    --radius-lg:       8px;
    --radius-xl:       12px;
    --radius-pill:     999px;

    /* shadow */
    --shadow-xs:       0 1px 1px rgba(17, 24, 39, 0.04);
    --shadow-sm:       0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-md:       0 4px 8px -2px rgba(17, 24, 39, 0.06), 0 2px 4px -2px rgba(17, 24, 39, 0.04);
    --shadow-lg:       0 12px 24px -8px rgba(17, 24, 39, 0.12), 0 4px 8px -4px rgba(17, 24, 39, 0.06);

    /* font */
    --font-ui:         'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body:       'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono:       'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

    --sidebar-width:   240px;
}

/* ---------- Dark theme ---------- */
[data-theme="dark"] {
    --brand:           #4ADE80;
    --brand-hover:     #22C55E;
    --brand-soft:      rgba(74, 222, 128, 0.10);
    --brand-soft-hover:rgba(74, 222, 128, 0.16);
    --brand-text-on:   #0F1419;

    --bg-page:         #0F172A;
    --bg-sidebar:      #0B1220;
    --bg-card:         #1E293B;
    --bg-subtle:       #1A2233;
    --bg-input:        #1E293B;
    --bg-hover:        #283449;
    --bg-row-hover:    #28344B;

    --border:          #334155;
    --border-strong:   #475569;
    --border-subtle:   #1F2A3D;
    --border-focus:    rgba(74, 222, 128, 0.4);

    --text:            #F1F5F9;
    --text-secondary:  #CBD5E1;
    --text-tertiary:   #94A3B8;
    --text-muted:      #64748B;

    --success:         #4ADE80;
    --success-bg:      rgba(74, 222, 128, 0.12);
    --success-border:  rgba(74, 222, 128, 0.30);
    --warn:            #FBBF24;
    --warn-bg:         rgba(251, 191, 36, 0.12);
    --warn-border:     rgba(251, 191, 36, 0.30);
    --danger:          #F87171;
    --danger-bg:       rgba(248, 113, 113, 0.12);
    --danger-border:   rgba(248, 113, 113, 0.30);
    --info:            #60A5FA;
    --info-bg:         rgba(96, 165, 250, 0.12);
    --info-border:     rgba(96, 165, 250, 0.30);

    --shadow-xs:       0 1px 1px rgba(0, 0, 0, 0.3);
    --shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md:       0 4px 8px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg:       0 12px 24px -8px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-page);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

::selection { background: var(--brand-soft); color: var(--text); }

/* スクロールバー */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* =============================================================================
   APP LAYOUT
   ============================================================================= */
.app {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar__brand-icon {
    width: 30px;
    height: 30px;
    background: var(--brand);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    color: var(--brand-text-on);
    font-weight: 700;
    font-family: var(--font-ui);
    font-size: 14px;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}
.sidebar__brand-text { flex: 1; min-width: 0; }
.sidebar__brand-title {
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}
.sidebar__brand-tagline {
    color: var(--text-tertiary);
    font-size: 11px;
    margin-top: 2px;
    line-height: 1.2;
}

.sidebar__section {
    padding: 18px 18px 6px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-family: var(--font-ui);
}

.sidebar__nav {
    padding: 0 10px;
    flex: 1;
    overflow-y: auto;
}
.sidebar__nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 11px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 1px;
    transition: background .12s, color .12s;
    cursor: pointer;
}
.sidebar__nav-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.sidebar__nav-item.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}
.sidebar__nav-item.is-active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 16px;
    background: var(--brand);
    border-radius: 0 2px 2px 0;
}
.sidebar__nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke-width: 1.75;
}

.sidebar__footer {
    border-top: 1px solid var(--border-subtle);
    padding: 12px;
}
.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
}
.sidebar__user-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-pill);
    background: var(--brand);
    color: var(--brand-text-on);
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 12px;
    font-family: var(--font-ui);
    flex-shrink: 0;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name {
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar__user-role {
    color: var(--text-tertiary);
    font-size: 11px;
}
.sidebar__icon-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    transition: background .12s, color .12s;
}
.sidebar__icon-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}
.sidebar__icon-btn svg { width: 16px; height: 16px; stroke-width: 1.75; }

.sidebar__actions {
    display: flex;
    gap: 4px;
    padding: 8px 4px 0;
    border-top: 1px solid var(--border-subtle);
    margin-top: 8px;
}

/* ---------- Main content ---------- */
.main { flex: 1; min-width: 0; }
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 40px 56px;
}

/* =============================================================================
   PAGE HEAD
   ----------------------------------------------------------------------------
   ページ側のマークアップが 2 パターンあるため両対応:
     A) <div class="page-head">
            <div class="page-head__eyebrow">…</div>
            <h1 class="page-head__title">…</h1>
            <p class="page-head__desc">…</p>
            <div class="page-head__actions">…</div>   (任意)
        </div>
     B) <div class="page-head">
            <div class="page-head__main">…</div>
            <div class="page-head__actions">…</div>   (任意)
        </div>
   どちらも、actions だけ右に、それ以外は左カラム縦並びにしたい。
   ============================================================================= */
.page-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 24px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
/* デフォルトで子要素は1カラム目 (縦に積み上がる) */
.page-head > *           { grid-column: 1; }
.page-head__main         { min-width: 0; }
/* actions のみ右カラム & 全行スパン */
.page-head > .page-head__actions {
    grid-column: 2;
    grid-row: 1 / -1;
    align-self: end;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.page-head__eyebrow {
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    font-family: var(--font-ui);
    margin: 0 0 6px;
}
.page-head__title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.25;
}
.page-head__desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 6px 0 0;
    max-width: 720px;
    line-height: 1.6;
}

/* =============================================================================
   KPI CARDS
   ============================================================================= */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    /* コンテナクエリで「カード幅が狭くなったら数値フォントを縮める」 */
    container-type: inline-size;
    min-width: 0;
}
.kpi__label {
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 10px;
}
.kpi__value {
    font-size: 28px;
    font-weight: 700;
    font-family: var(--font-ui);
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.1;
    /* 桁数が大きい場合に親カード内で折り返す/省略させる */
    overflow-wrap: anywhere;
    word-break: break-word;
}
/* コンテナクエリ: カード幅 (≒ 列幅) に合わせて自動縮小 */
@container (max-width: 180px) {
    .kpi__value { font-size: 24px; }
}
@container (max-width: 150px) {
    .kpi__value { font-size: 20px; }
}
@container (max-width: 120px) {
    .kpi__value { font-size: 18px; letter-spacing: -0.03em; }
}
.kpi__sub {
    color: var(--text-tertiary);
    font-size: 11px;
    margin-top: 6px;
}
.kpi--alert .kpi__value { color: var(--warn); }
.kpi--ok    .kpi__value { color: var(--success); }
.kpi--info  .kpi__value { color: var(--info); }

/* =============================================================================
   CARDS
   ============================================================================= */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    overflow: hidden;
}
.card__inner { padding: 18px 20px; }
/* card 内の form は card__inner 相当の padding を持つ */
.card > form:not(.no-pad) { padding: 18px 20px; }
.card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
    gap: 12px;
    flex-wrap: wrap;
}
.card__title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

/* =============================================================================
   ANALYTICS CHART
   ============================================================================= */
.chart-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.chart-summary__stats {
    display: flex;
    gap: 32px;
    flex-wrap: wrap;
}
.chart-stat__label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-ui);
    margin-bottom: 4px;
}
.chart-stat__swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}
.chart-stat__hint {
    color: var(--text-muted);
    font-size: 10px;
    cursor: help;
    margin-left: 2px;
}
.chart-stat__swatch--pv { background: var(--brand); }
.chart-stat__swatch--uu {
    background: transparent;
    border: 2px solid var(--info);
    border-radius: 50%;
    width: 10px;
    height: 10px;
}
.chart-stat__value {
    font-size: 26px;
    font-weight: 700;
    font-family: var(--font-ui);
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1;
}
.chart-summary__sub {
    font-size: 12px;
    color: var(--text-tertiary);
    text-align: right;
    line-height: 1.5;
}

.chart-wrap {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    margin-top: 8px;
}
.analytics-chart {
    width: 100%;
    height: auto;
    max-height: 240px;
    display: block;
}
.analytics-chart rect {
    transition: opacity .12s, fill .15s;
}
.analytics-chart rect:hover {
    opacity: 1 !important;
    filter: brightness(1.08);
}

/* =============================================================================
   TABLES
   ============================================================================= */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    text-align: left;
    padding: 11px 20px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}
th {
    background: var(--bg-subtle);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: var(--font-ui);
    padding: 10px 20px;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--bg-row-hover); }
tbody tr:last-child td { border-bottom: none; }
table a { color: var(--text); font-weight: 500; }
table a:hover { color: var(--brand); text-decoration: underline; }

/* =============================================================================
   BADGES (装飾なし、ステータスのみ)
   ============================================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-ui);
    border: 1px solid;
    letter-spacing: 0.01em;
    line-height: 1.5;
}
.badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}
.badge--no-dot::before { display: none; }

/* status (pairing) */
.badge--issued    { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }
.badge--approved  { background: var(--info-bg);    color: var(--info);    border-color: var(--info-border); }
.badge--activated { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge--rejected  { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-border); }
.badge--expired   { background: var(--bg-subtle);  color: var(--text-tertiary); border-color: var(--border); }
.badge--active    { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge--suspended { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }
.badge--terminated{ background: var(--bg-subtle);  color: var(--text-tertiary); border-color: var(--border); }
.badge--demo      { background: var(--info-bg);    color: var(--info);    border-color: var(--info-border); }

/* plan */
.badge--Free      { background: var(--bg-subtle); color: var(--text-secondary); border-color: var(--border); }
.badge--Standard  { background: var(--info-bg);    color: var(--info);    border-color: var(--info-border); }
.badge--Premium   { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge--Premium\+ { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge--Custom    { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }
.badge--Demo      { background: var(--bg-subtle); color: var(--text-tertiary); border-color: var(--border); }

/* article status */
.badge--draft     { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }
.badge--published { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.badge--archived  { background: var(--bg-subtle); color: var(--text-tertiary); border-color: var(--border); }

/* tag */
.badge--tag {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: transparent;
    font-weight: 500;
    font-size: 10px;
}
.badge--tag::before { display: none; }

/* =============================================================================
   BUTTONS
   ============================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    font-family: var(--font-ui);
    text-decoration: none;
    transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
    white-space: nowrap;
}
.btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}
.btn:disabled { cursor: not-allowed; opacity: 0.5; }

.btn--primary {
    background: var(--brand);
    color: var(--brand-text-on);
    box-shadow: var(--shadow-xs);
}
.btn--primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn--ghost {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
}
.btn--ghost:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn--danger {
    background: var(--bg-card);
    color: var(--danger);
    border-color: var(--danger-border);
}
.btn--danger:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--xs { padding: 3px 8px; font-size: 11px; }

.btn__icon { width: 14px; height: 14px; stroke-width: 2; flex-shrink: 0; }

/* =============================================================================
   FORM FIELDS
   ============================================================================= */
.field { margin-bottom: 16px; }
.field__label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.field__required { color: var(--danger); margin-left: 2px; }
.field__input,
.field__select,
.field__textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: var(--font-body);
    background: var(--bg-input);
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
    line-height: 1.4;
}
.field__input::placeholder,
.field__textarea::placeholder { color: var(--text-muted); }
.field__input:focus,
.field__select:focus,
.field__textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--border-focus);
}
.field__textarea { resize: vertical; min-height: 80px; }
.field__hint { font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }
.field__error { font-size: 12px; color: var(--danger); margin-top: 6px; }

/* =============================================================================
   ALERTS
   ============================================================================= */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.7;
    border: 1px solid;
}
/* 注意: 親 .alert に display:flex を付けると、<strong> や地の文がそれぞれ
   別 flex item に切り出されて、長文では各 item が 1 列ずつ細く積まれる
   現象 (改行崩れ) を起こす。アイコン + 本文を flex で並べたい場合は
   内部要素を明示する:
     <div class="alert alert--warn">
       <span class="alert__icon">⚠️</span>
       <div class="alert__body">本文 <strong>強調</strong> 本文</div>
     </div>
*/
.alert__icon { display: inline-block; margin-right: 6px; vertical-align: top; }
.alert__body { display: inline; }
.alert--error   { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger-border); }
.alert--info    { background: var(--info-bg);    color: var(--info);    border-color: var(--info-border); }
.alert--success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.alert--warn    { background: var(--warn-bg);    color: var(--warn);    border-color: var(--warn-border); }

/* =============================================================================
   EMPTY STATE
   ============================================================================= */
.empty {
    text-align: center;
    padding: 56px 24px;
    color: var(--text-tertiary);
}
.empty__icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-radius: var(--radius-pill);
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    font-size: 22px;
}
.empty__icon svg { width: 22px; height: 22px; stroke-width: 1.5; }
.empty__title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty__desc  { font-size: 12px; color: var(--text-tertiary); }

/* =============================================================================
   MODAL
   ============================================================================= */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: modal-fade-in .15s ease-out;
}
[data-theme="dark"] .modal-mask { background: rgba(0, 0, 0, 0.65); }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px 28px;
    box-shadow: var(--shadow-lg);
    animation: modal-pop-in .18s ease-out;
}
.modal__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}
.modal__title { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.modal__close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.modal__close:hover { background: var(--bg-hover); color: var(--text); }
.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   LOGIN PAGE
   ============================================================================= */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-subtle);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-card__logo {
    width: 42px;
    height: 42px;
    background: var(--brand);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    color: var(--brand-text-on);
    font-weight: 700;
    font-family: var(--font-ui);
    font-size: 18px;
    letter-spacing: -0.02em;
    margin-bottom: 18px;
}
.login-card h1 {
    font-size: 19px;
    font-weight: 700;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
    color: var(--text);
}
.login-card__sub {
    color: var(--text-tertiary);
    font-size: 13px;
    margin: 0 0 24px;
}
.login-card .btn { width: 100%; padding: 10px 16px; font-size: 14px; }

/* =============================================================================
   UTILITY
   ============================================================================= */
.mono {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--bg-subtle);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--text-secondary);
}

/* =============================================================================
   SECRET DISPLAY
   ============================================================================= */
.secret-display {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 10px 0;
}
.secret-display__label {
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 4px;
    font-family: var(--font-ui);
}
.secret-display__value {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    word-break: break-all;
}
.secret-display__copy { margin-top: 8px; display: flex; justify-content: flex-end; }

/* テーマ切替アイコンの表示制御 */
.is-theme-light .theme-icon-light,
.is-theme-dark  .theme-icon-dark { display: none; }

/* =============================================================================
   RESPONSIVE LAYOUT HELPERS
   ============================================================================= */

/* 2列フォーム (220px 未満になったら自動で1列に) */
.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

/* テーブルを含む動的コンテナを横スクロール対応
   (.card 内の <table> 直下を囲む div, または table 自体を含む div) */
.card > div:has(> table),
.card > [id$="-table"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.card > div:has(> table) table,
.card > [id$="-table"] table {
    min-width: 640px;
}

/* =============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================= */

/* --- < 1100px: サイドバーをアイコンのみに折り畳む ---------------------------- */
@media (max-width: 1100px) {
    :root { --sidebar-width: 64px; }

    .sidebar__brand { justify-content: center; padding: 18px 0 14px; }
    .sidebar__brand-text { display: none; }

    .sidebar__section { display: none; }

    .sidebar__nav { padding: 8px 8px; }
    .sidebar__nav-item {
        justify-content: center;
        padding: 9px;
        gap: 0;
    }
    /* ナビ項目のラベル (icon 直後の <span>) を隠す。tooltip 化 */
    .sidebar__nav-item > span:not(.sidebar__nav-icon) { display: none; }
    /* アクティブの左バーは折り畳み時に位置が崩れるため、背景ハイライトのみに */
    .sidebar__nav-item.is-active::before { display: none; }

    .sidebar__footer { padding: 10px 8px; }
    .sidebar__user { justify-content: center; padding: 4px; }
    .sidebar__user-info { display: none; }
    .sidebar__actions {
        flex-direction: column;
        gap: 4px;
        padding: 8px 0 0;
        align-items: center;
    }
    .sidebar__actions > .sidebar__icon-btn[style] { margin-left: 0 !important; }

    .main-content { padding: 28px 28px 48px; }
    .page-head__title { font-size: 22px; }
}

/* =============================================================================
   MOBILE TOPBAR & DRAWER BACKDROP (デフォルトは非表示、< 640px で出現)
   ============================================================================= */
.mobile-topbar  { display: none; }
.sidebar-backdrop { display: none; }

/* --- < 720px: タブレット縦 / スマホ -------------------------------------------- */
@media (max-width: 720px) {
    .main-content { padding: 20px 16px 40px; }
    .page-head {
        grid-template-columns: 1fr;   /* 単列に */
        row-gap: 8px;
        margin-bottom: 18px;
        padding-bottom: 16px;
    }
    .page-head__title { font-size: 20px; }
    .page-head > .page-head__actions {
        grid-column: 1;
        grid-row: auto;
        align-self: stretch;
        margin-top: 6px;
        justify-content: flex-start;
    }
    .page-head > .page-head__actions .btn { flex: 1; justify-content: center; }

    .kpis { gap: 10px; }
    .kpi { padding: 14px; }
    .kpi__value { font-size: 24px; }

    .card__head, .card__inner { padding: 14px 16px; }
    .card > form { padding: 14px 16px; }
    th, td { padding: 10px 14px; }

    .modal { padding: 20px 18px; border-radius: var(--radius-lg); }
    .modal__head { margin-bottom: 14px; }
}

/* --- < 640px: スマホ → サイドバーを drawer 化 + 上部にトップバー ----------- */
@media (max-width: 640px) {
    /* レイアウト上は左カラム幅を持たない (drawer は overlay) */
    :root { --sidebar-width: 0px; }

    /* 上部のミニトップバー: ハンバーガー + ブランド名 + ログアウト */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 60;
    }
    .mobile-topbar__hamburger {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        width: 36px;
        height: 36px;
        display: grid;
        place-items: center;
        cursor: pointer;
        color: var(--text);
        padding: 0;
        flex-shrink: 0;
    }
    .mobile-topbar__hamburger:hover { background: var(--bg-hover); }
    .mobile-topbar__hamburger svg { width: 18px; height: 18px; stroke-width: 1.75; }
    .mobile-topbar__brand {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
        min-width: 0;
    }
    .mobile-topbar__brand-icon {
        width: 28px; height: 28px;
        background: var(--brand);
        border-radius: var(--radius-md);
        display: grid; place-items: center;
        color: var(--brand-text-on);
        font-weight: 700;
        font-family: var(--font-ui);
        font-size: 13px;
        flex-shrink: 0;
    }
    .mobile-topbar__brand-title {
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* サイドバー: 画面外に隠す → .is-open でスライドイン */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        height: 100vh;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform .22s ease-out;
        box-shadow: var(--shadow-lg);
        /* drawer 内のスクロールは独立 */
        overflow-y: auto;
    }
    .sidebar.is-open { transform: translateX(0); }

    /* drawer 表示時は中身を「展開モード」に戻す (< 1100 で icon-only にした override を打ち消す) */
    .sidebar__brand { justify-content: flex-start; padding: 20px 18px 16px; }
    .sidebar__brand-text { display: block; }
    .sidebar__section { display: block; }
    .sidebar__nav { padding: 0 10px; }
    .sidebar__nav-item {
        justify-content: flex-start;
        padding: 11px 14px;       /* タッチ向けに少し広く */
        gap: 12px;
    }
    .sidebar__nav-item > span:not(.sidebar__nav-icon) { display: inline; }
    .sidebar__nav-item.is-active::before { display: block; }
    .sidebar__footer { padding: 12px; }
    .sidebar__user { justify-content: flex-start; padding: 6px 10px; }
    .sidebar__user-info { display: block; }
    .sidebar__actions {
        flex-direction: row;
        gap: 4px;
        padding: 8px 4px 0;
        align-items: stretch;
    }
    .sidebar__actions > .sidebar__icon-btn[style] { margin-left: auto !important; }

    /* バックドロップ: drawer 外をタップで閉じる */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 150;
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s;
    }
    [data-theme="dark"] .sidebar-backdrop { background: rgba(0, 0, 0, 0.65); }
    .sidebar-backdrop.is-shown {
        opacity: 1;
        pointer-events: auto;
    }

    /* drawer 開いている間は背面スクロールを止める */
    body.is-sidebar-open { overflow: hidden; }

    /* メインコンテンツ: サイドバー幅 0 で full width に */
    .main-content { padding: 16px 14px 32px; }
    .page-head__title { font-size: 19px; }

    /* KPI: 強制的に 2x2 グリッドに */
    .kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .kpi { padding: 14px; }
    /* kpi__value は container query で自動調整するので明示指定なし */

    th, td { padding: 9px 12px; font-size: 12px; }

    /* タッチ向けに最小ボタンサイズを確保 */
    .btn { min-height: 36px; }
    .btn--sm { min-height: 32px; }
}
