/* ================================================================
   KK Procurement v2 — Main Stylesheet
   Style reference: CRM ค่าใช้จ่าย (dark sidebar + clean content)
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
    /* Sidebar — deep green (warm natural tone, not dark blue-gray) */
    --sidebar-bg: #2d3e1a;
    --sidebar-bg-hover: #3f5527;
    --sidebar-bg-active: #ff8829;         /* bright orange = active item */
    --sidebar-text: #d4e3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-section: #8ea563;
    --sidebar-accent: #a5c90f;            /* lime — for section-header dividers */

    --content-bg: #fbf8f4;                /* warm cream (was cool gray) */
    --card-bg: #ffffff;
    --border: #e8e1d4;
    --border-light: #f5f1ea;

    --text: #1f2937;
    --text-muted: #6b7280;
    --text-soft: #9ca3af;

    /* Primary = warm orange */
    --primary: #fe6b40;
    --primary-hover: #e85628;
    --primary-soft: #ffedd5;

    /* Secondary green palette */
    --accent-green: #6f9c3d;
    --accent-green-soft: #ecf5d9;
    --accent-lime: #a5c90f;

    /* Status colors (keep semantic meaning) */
    --green:  #6f9c3d;                    /* success → natural green */
    --green-soft: #ecf5d9;
    --yellow: #d97706;
    --yellow-soft: #fef3c7;
    --red:    #dc2626;
    --red-soft: #fee2e2;
    --gray:   #6b7280;
    --gray-soft: #f3f4f6;

    --orange: #fe6b40;
    --orange-soft: #ffedd5;

    --sidebar-w: 260px;
    --topbar-h: 60px;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -2px rgba(0,0,0,0.04);
}

body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--content-bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ================================================================
   Layout
   ================================================================ */

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

/* ============ Sidebar ============ */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #2d3e1a 0%, #1f2e12 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    overflow-y: auto;
    z-index: 10;
    border-right: 3px solid var(--accent-lime);
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(165,201,15,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-logo {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #fe6b40 0%, #ff8829 100%);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(254,107,64,0.35);
}
.sidebar-title {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}
.sidebar-subtitle {
    color: var(--sidebar-section);
    font-size: 11px;
    letter-spacing: .5px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
}
.nav-section {
    color: var(--accent-lime);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 14px 10px 8px;
    opacity: 0.8;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 2px;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, color .15s, transform .1s;
    text-decoration: none;
    position: relative;
}
.nav-item:hover {
    background: var(--sidebar-bg-hover);
    color: #fff;
    text-decoration: none;
}
.nav-item.active {
    background: linear-gradient(90deg, #fe6b40 0%, #ff8829 100%);
    color: var(--sidebar-text-active);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(254,107,64,0.3);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 4px; bottom: 4px;
    width: 3px;
    background: var(--accent-lime);
    border-radius: 0 2px 2px 0;
}
.nav-item .ico {
    width: 20px; height: 20px;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}
.nav-item .ico svg {
    width: 18px; height: 18px;
    stroke-width: 1.8;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.05);
    color: var(--sidebar-section);
    font-size: 11px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    font-size: 13px;
}
.user-avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

/* ============ Main ============ */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0; z-index: 5;
}
.topbar-toggle {
    display: none;
    background: none; border: none;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 20px;
}
.topbar-title {
    font-size: 17px;
    font-weight: 500;
}
.topbar-spacer { flex: 1; }

.content {
    flex: 1;
    padding: 24px 28px;
}

/* ================================================================
   Cards
   ================================================================ */

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.card-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 20px; }

/* ================================================================
   KPI cards (dashboard stat boxes)
   ================================================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 14px;
    align-items: center;
}
.kpi-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 22px;
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-label { color: var(--text-muted); font-size: 13px; margin-bottom: 4px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text); }
.kpi-delta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.kpi-blue .kpi-icon   { background: var(--primary-soft); color: var(--primary); }
.kpi-green .kpi-icon  { background: var(--green-soft); color: var(--green); }
.kpi-yellow .kpi-icon { background: var(--yellow-soft); color: var(--yellow); }
.kpi-red .kpi-icon    { background: var(--red-soft); color: var(--red); }
.kpi-orange .kpi-icon { background: var(--orange-soft); color: var(--orange); }
.kpi-gray .kpi-icon   { background: var(--gray-soft); color: var(--gray); }

/* ================================================================
   Filter bar (search + dropdowns)
   ================================================================ */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    background: #fff;
}
.filter-bar input,
.filter-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.filter-bar input:focus,
.filter-bar select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.filter-bar .search-group {
    flex: 1;
    min-width: 220px;
    position: relative;
}
.filter-bar .search-group input {
    width: 100%;
    padding-left: 36px;
}
.filter-bar .search-group::before {
    content: '';
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') no-repeat center;
    background-size: 14px;
}

/* ================================================================
   Buttons
   ================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
    text-decoration: none;
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover   { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--gray-soft); }
.btn-ghost     { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--gray-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* icon-only action buttons (list rows) */
.btn-icon {
    width: 30px; height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s, transform .15s;
    padding: 0;
    margin: 0 2px;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon.view { background: var(--green-soft); color: var(--green); }
.btn-icon.edit { background: var(--primary-soft); color: var(--primary); }
.btn-icon.del  { background: var(--red-soft); color: var(--red); }
.btn-icon:hover { filter: brightness(.95); transform: translateY(-1px); }

/* Period pills (dashboard) */
.period-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.period-pill {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    background: #fff;
    text-decoration: none;
}
.period-pill:hover {
    background: var(--gray-soft);
    text-decoration: none;
}
.period-pill.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ================================================================
   Tables
   ================================================================ */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.table th {
    background: #fafbfc;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}
.table tbody tr { transition: background-color .12s; }
.table tbody tr:hover { background: #fafbfc; }
.table .right { text-align: right; }
.table .center { text-align: center; }
.table .nowrap { white-space: nowrap; }

.table-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-soft);
}
.table-empty .emoji { font-size: 40px; margin-bottom: 12px; display: block; }

/* Product row mini parts */
.product-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}
.product-thumb {
    width: 48px; height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--gray-soft);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.product-thumb-placeholder {
    width: 48px; height: 48px;
    border-radius: var(--radius-sm);
    background: var(--gray-soft);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-soft);
    flex-shrink: 0;
}
.product-name { font-weight: 500; color: var(--text); }
.product-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.product-id   { font-family: ui-monospace, 'Cascadia Code', 'Courier New', monospace;
                color: var(--primary); font-size: 13px; font-weight: 500; }

/* ================================================================
   Badges
   ================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-red    { background: var(--red-soft);    color: var(--red); }
.badge-blue   { background: var(--primary-soft);color: var(--primary); }
.badge-gray   { background: var(--gray-soft);   color: var(--gray); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-purple { background: #ede9fe;             color: #7c3aed; }

/* ================================================================
   Pagination
   ================================================================ */

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 13px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-links { display: inline-flex; gap: 4px; }
.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px; height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    background: #fff;
    text-decoration: none;
    font-size: 13px;
}
.page-link:hover { background: var(--gray-soft); text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link.disabled { color: var(--text-soft); pointer-events: none; }

/* ================================================================
   Detail view — product view page
   ================================================================ */

.detail-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
}
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

.gallery-main {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    background: var(--gray-soft);
    object-fit: cover;
    border: 1px solid var(--border);
}
.gallery-thumbs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 10px;
}
.gallery-thumbs img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    opacity: .7;
}
.gallery-thumbs img.active { opacity: 1; border-color: var(--primary); }

.info-list { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.info-list dt { color: var(--text-muted); font-size: 13px; }
.info-list dd { margin: 0; color: var(--text); font-size: 14px; }

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin: 24px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}

.pricing-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}
.pricing-table th, .pricing-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}
.pricing-table th { background: #fafbfc; font-weight: 600; color: var(--text-muted); font-size: 12px; }
.pricing-table .right { text-align: right; font-weight: 500; }

.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 12px;
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}
.activity-icon.shop    { background: var(--primary-soft); color: var(--primary); }
.activity-icon.comment { background: var(--orange-soft); color: var(--orange); }
.activity-body { flex: 1; }
.activity-meta { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
.activity-text { color: var(--text); font-size: 14px; line-height: 1.5; white-space: pre-wrap; }

/* ================================================================
   Responsive
   ================================================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s;
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar-toggle { display: inline-flex; }
    .content { padding: 16px; }
}
