:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --line: #e4eaf2;
    --line-strong: #d7deea;
    --text: #223044;
    --muted: #6a778b;
    --brand: #004483;
    --brand-strong: #003666;
    --brand-soft: #e9eff5;
    --danger: #d93b3b;
    --success: #1f9f67;
    --warning: #eb9c2d;
    --shadow-soft: 0 8px 24px rgba(20, 44, 86, 0.08);
}

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

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    font-family: "Pretendard Variable", "Noto Sans KR", "Segoe UI", "Malgun Gothic", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 0% -10%, #dae8ff 0%, transparent 36%),
        radial-gradient(circle at 100% 0%, #edf3ff 0%, transparent 30%),
        var(--bg);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.shell-body {
    flex: 1;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    background: linear-gradient(180deg, #f8fbff 0%, #f3f7fe 100%) 0 0 / 280px 100% no-repeat;
}

.sidebar {
    border-right: none;
    background: linear-gradient(180deg, #f8fbff 0%, #f3f7fe 100%);
    padding: 0.9rem 12px 100px 12px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 58px;
    align-self: start;
    max-height: calc(100vh - 58px);
    overflow-y: auto;
    z-index: 50;
}

.topbar-brand {
    display: flex;
    align-items: center;
    min-width: 0;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.42rem;
    text-decoration: none;
    color: inherit;
    padding: 0.3rem 0.5rem;
    margin: -0.3rem -0.5rem;
    border-radius: 10px;
    transition: background-color 0.18s ease;
}

.brand-link:hover {
    background: #f3f7fe;
}

.brand-link:focus-visible {
    outline: 2px solid #7ea7dd;
    outline-offset: 3px;
    border-radius: 10px;
}

.brand-mark img {
    height: 29px;
    width: auto;
    max-width: 152px;
    display: block;
    object-fit: contain;
}

.brand-text-group {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 0.34rem;
    white-space: nowrap;
}

.topbar-brand h1 {
    margin-top: 0;
    font-size: 1.12rem;
    font-weight: 800;
    line-height: 1;
}

.brand-partner {
    color: #004483;
}

.brand-data {
    color: #404040;
}

.brand-dot {
    margin-left: 1px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: #35506f;
    padding: 0.62rem 0.75rem;
    border-radius: 8px;
    border-left: 3px solid transparent;
    font-size: 0.92rem;
    font-weight: 600;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.nav-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #97a3b5;
    transition: color 0.18s ease;
}

.nav-label {
    display: block;
    min-width: 0;
}

.sidebar-nav a .nav-sub {
    display: block;
    margin-top: 0.15rem;
    font-size: 11px;
    font-weight: 500;
    color: #888;
    transition: color 0.18s ease;
}

.sidebar-nav a:hover {
    background: #f9fafb;
}

.sidebar-nav a.active {
    background: var(--brand-soft);
    border-left-color: var(--brand);
    color: var(--brand-strong);
}

.sidebar-nav a.active .nav-icon {
    color: var(--brand-strong);
}

.sidebar-nav a.active .nav-sub {
    color: var(--brand-strong);
    opacity: 0.75;
}

/* 하위 메뉴가 있는 사이드바 그룹(Contracts, Material Trends) 트리 메뉴.
   그룹 이름 클릭 시 첫 번째 하위 항목으로 이동하고, 화살표 버튼은 별도로
   펼침/접힘만 토글한다(둘 다 <a> 안에 넣으면 중첩 인터랙티브 요소가 되어
   버튼처럼 별도 형제 요소로 둔다). */
.nav-group-row {
    display: flex;
    align-items: stretch;
    border-radius: 8px;
    border-left: 3px solid transparent;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.nav-group-row:hover {
    background: #f9fafb;
}

.nav-group-row.active {
    background: var(--brand-soft);
    border-left-color: var(--brand);
}

.nav-group-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex: 1 1 auto;
    min-width: 0;
    text-decoration: none;
    color: #35506f;
    padding: 0.62rem 0.75rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.nav-group-row.active .nav-group-link,
.nav-group-row.active .nav-icon {
    color: var(--brand-strong);
}

.nav-group-row.active .nav-sub {
    color: var(--brand-strong);
    opacity: 0.75;
}

.nav-chevron-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    border: none;
    background: transparent;
    color: #97a3b5;
    cursor: pointer;
    padding: 0;
}

.nav-chevron-btn:hover {
    color: var(--brand);
}

.nav-chevron {
    transition: transform 0.18s ease;
}

.nav-chevron-btn[aria-expanded="true"] .nav-chevron {
    transform: rotate(90deg);
}

.nav-subtree {
    position: relative;
    display: grid;
    gap: 2px;
    margin: 2px 0 6px;
    padding-left: 41px;
}

/* display를 명시한 요소는 [hidden] 기본 규칙보다 우선하므로 명시적으로 되살림 */
.nav-subtree[hidden] {
    display: none;
}

.nav-subtree::before {
    content: '';
    position: absolute;
    left: 27px;
    top: 0;
    bottom: 6px;
    width: 1px;
    background: #d7dae6;
}

/* .sidebar-nav a(부모 항목)와 특이도가 같은 클래스 하나짜리 선택자로는 밀리므로,
   .sidebar-nav로 한 번 더 묶어서 border-radius/font-size/font-weight가 부모
   항목 스타일에 덮이지 않도록 한다 */
.sidebar-nav .nav-sub-item {
    display: block;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.5;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav .nav-sub-item:hover {
    background: #eceffa;
    color: var(--brand-strong);
}

.sidebar-nav .nav-sub-item.active {
    background: var(--brand);
    color: #ffffff;
    font-weight: 700;
}

.sidebar-footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    background: #f3f7fe;
    border-top: 1px solid var(--line);
    padding: 0.75rem 0.7rem 0.9rem;
}

/* 신규입력/수정/삭제 등 쓰기 기능 트리거. 관리자(role=admin)가 아니면 숨긴다.
   실제 막는 건 서버 쪽 role 체크(app/access_control.py의 is_admin_user)이고,
   이건 화면에서만 안 보이게 하는 것이다. */
body:not([data-user-role="admin"]) .admin-only {
    display: none !important;
}

.topbar-user {
    position: relative;
    flex: none;
}

.topbar-user-trigger {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.5rem;
    margin: -0.3rem -0.5rem;
    border-radius: 10px;
}

.topbar-user-trigger:hover {
    background: #f3f7fe;
}

.topbar-avatar {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand-strong);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
}

.topbar-user-text {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 0.3rem;
}

.topbar-user-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.topbar-user-sep {
    font-size: 11px;
    color: var(--line-strong);
}

.topbar-user-dept {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.topbar-user-chevron {
    flex: none;
    color: var(--muted);
}

.topbar-user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-soft);
    padding: 0.35rem;
    z-index: 60;
}

.topbar-dropdown-item {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.topbar-dropdown-item:hover {
    background: var(--brand-soft);
    color: var(--brand);
}

.sidebar-watermark {
    display: block;
    width: 36px;
    height: 36px;
    margin: 0.4rem auto 0.7rem;
    opacity: 0.08;
    pointer-events: none;
    position: relative;
    z-index: 0;
}

.sidebar-footer p {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.07em;
}

.sidebar-footer strong {
    display: inline-block;
    margin-top: 0.2rem;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
}

.workspace {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 58px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0 2rem 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.header-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.34rem 0.68rem;
    border-radius: 999px;
    border: 1px solid #fbbf24;
    color: #92400e;
    background: #fffbeb;
    font-size: 0.78rem;
    font-weight: 700;
}

.header-chip svg {
    flex: 0 0 auto;
}

.container {
    width: 100%;
    margin: 0;
    padding: 0.45rem 1rem 1rem;
}

.content {
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    padding: 0.65rem 1rem 1rem;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    position: sticky;
    top: 58px;
    z-index: 20;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 10px -8px rgba(20, 44, 86, 0.18);
    margin: -0.65rem 0 0.7rem;
    padding: 0.65rem 0 0.65rem;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: #1d3557;
    margin-bottom: 0.18rem;
}

.page-subtitle {
    color: var(--muted);
    font-size: 0.92rem;
}

/* 사이드바 트리 메뉴로 옮긴 화면(Contracts, Material Trends 등)의 현재 보기 모드를
   페이지 제목 옆에 작게 표시한다 (예: "Contracts · 협력사 기준 조회") */
.page-mode-label {
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--brand);
    margin-left: 0.4rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.8rem;
}

.metric-card {
    background: linear-gradient(180deg, #f4f9ff 0%, #ffffff 100%);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.85rem 0.9rem;
}

.metric-card .value {
    font-size: 1.3rem;
    font-weight: 800;
    color: #004483;
    margin-bottom: 0.15rem;
}

.metric-card .label {
    color: var(--muted);
    font-size: 0.88rem;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
    padding: 0.9rem;
}

.btn {
    display: inline-block;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--brand);
    color: #ffffff;
    padding: 0.52rem 0.82rem;
    margin: 0.25rem 0.25rem 0.25rem 0;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
    background: var(--brand-strong);
}

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

.btn-success:hover {
    background: #198c5a;
}

.btn-secondary {
    background: #ffffff;
    color: #34506e;
    border-color: #d6e0ed;
}

.btn-secondary:hover {
    background: #eef3fa;
}

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

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

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    padding: 0.56rem 0.66rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(0, 68, 131, 0.14);
}

label {
    display: inline-block;
    margin-bottom: 0.3rem;
    font-size: 0.84rem;
    font-weight: 700;
    color: #314966;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.8rem;
    background: #ffffff;
    border: 1px solid #dfe7f3;
    border-radius: 10px;
    overflow: hidden;
}

table th {
    background: #f2f6fc;
    color: #365170;
    font-size: 0.83rem;
    font-weight: 800;
    text-transform: none;
    padding: 0.72rem 0.72rem;
    border-bottom: 1px solid #dfe7f3;
}

table td {
    padding: 0.7rem 0.72rem;
    border-bottom: 1px solid #ebf0f7;
    font-size: 0.9rem;
    vertical-align: top;
}

table tr:hover {
    background: #f8fbff;
}

.chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: var(--brand-soft);
    color: #004483;
    border: 1px solid #c7d6e6;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.28rem 0.56rem;
}

.muted {
    color: var(--muted);
}

/* 선택형 토글/탭 버튼(조회 기준, 품목 탭, 기간 필터, 폼 탭 등) 공용 모서리 값.
   각 화면은 자체 색상/패딩을 유지하되 border-radius만 이 값을 참조해서
   완전 타원(999px) 배지와 시각적으로 구분되도록 한다. */
.seg-toggle-btn {
    border-radius: 10px;
}

@media (max-width: 1100px) {
    .shell-body {
        grid-template-columns: 1fr;
        background: none;
    }

    .sidebar {
        position: static;
        height: auto;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--line);
        padding-bottom: 0.8rem;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.35rem;
        overflow-x: auto;
    }

    .sidebar-nav a {
        white-space: nowrap;
    }

    /* 좁은 화면에서도 트리 메뉴를 유지한다. 그룹 행(아이콘+라벨+화살표)은
       가로 아이콘 탭 목록의 한 칸을 그대로 차지하고, 하위 메뉴는 화살표를
       눌렀을 때 그리드 전체 폭을 차지하는 줄로 펼쳐진다. */
    .nav-group {
        display: contents;
    }

    .nav-group-link {
        white-space: nowrap;
    }

    .nav-subtree {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        padding-left: 0;
        margin: 0.1rem 0 0.2rem;
    }

    .nav-subtree::before {
        display: none;
    }

    .nav-subtree[hidden] {
        display: none;
    }

    .sidebar-nav .nav-sub-item {
        white-space: nowrap;
    }

    .sidebar-footer {
        display: none;
    }
}

@media (max-width: 800px) {
    .topbar {
        height: 96px;
        padding: 0.7rem 0.85rem;
        align-items: flex-start;
        justify-content: flex-start;
        flex-direction: column;
        gap: 0.45rem;
    }

    .page-head {
        top: 96px;
        margin: -0.75rem 0 0.7rem;
        padding: 0.65rem 0 0.65rem;
    }

    .container {
        padding: 0.75rem;
    }

    .content {
        padding: 0.75rem;
    }

    .sidebar-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .sidebar-nav {
        grid-template-columns: 1fr;
    }
}
