/* DFL - Knack-Style Design System */
/* Based on BCGG UI Specification */

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

:root {
    /* Colors - Knack style */
    --color-primary: rgb(67, 161, 198);       /* #43a1c6 - links, icons */
    --color-primary-btn: rgb(87, 191, 154);   /* #57bf9a - Nav bg, action buttons */
    --color-text: rgb(74, 74, 74);            /* #4a4a4a - body text */
    --color-text-dark: rgb(54, 54, 54);       /* #363636 - headings, table */
    --color-text-gray: rgb(128, 128, 128);    /* #808080 - muted text */
    --color-border: rgba(0, 0, 0, 0.15);      /* table borders */
    --color-border-btn: rgb(219, 219, 219);   /* #dbdbdb - button borders */
    --color-bg-white: rgb(255, 255, 255);
    --color-bg-header: rgb(239, 241, 243);    /* #eff1f3 - table headers */
    --color-bg-alt-row: rgb(250, 250, 250);   /* #fafafa - alternating rows */
    --color-save-btn: rgb(236, 230, 166);     /* #ece6a6 - save button bg */
    --color-cancel-btn: rgb(224, 204, 204);   /* #e0cccc - cancel button bg */

    /* Typography */
    --font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-base: 14px;
    --font-size-small: 12px;
    --font-size-nav: 16px;
    --font-size-title: 28px;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background-color: var(--color-bg-white);
    line-height: 1.5;
}

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

a:hover {
    text-decoration: underline;
}

/* ========================================
   HEADER / NAVIGATION - Green Background
   ======================================== */

.app-header {
    background-color: var(--color-primary-btn);
    padding: 0 20px;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 0;
}

.app-logo {
    font-size: 20px;
    font-weight: 700;
    color: white;
    text-decoration: none;
    padding: 12px 20px 12px 0;
}

.app-logo:hover {
    text-decoration: none;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 0;
}

.main-nav a {
    color: white;
    font-size: var(--font-size-nav);
    font-weight: 400;
    text-decoration: none;
    padding: 12px 18px;
    transition: background-color 0.15s;
}

.main-nav a:hover {
    background-color: rgba(255, 255, 255, 0.15);
    text-decoration: none;
}

.main-nav a.active {
    background-color: rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

.user-area {
    color: rgba(255, 255, 255, 0.9);
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-area a {
    color: white;
}

.user-area a:hover {
    text-decoration: underline;
}

.user-area .fa-cog {
    font-size: 18px;
    cursor: pointer;
    margin-left: 4px;
}

.user-area .fa-cog:hover {
    opacity: 0.8;
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content {
    padding: 20px;
}

/* ========================================
   VIEW SECTION
   ======================================== */

.view-section {
    margin-bottom: 40px;
}

.view-action-btn {
    display: inline-block;
    background-color: var(--color-primary-btn);
    color: white;
    padding: 12px 24px;
    font-size: var(--font-size-nav);
    font-weight: 400;
    border-radius: 4px;
    text-decoration: none;
    margin-bottom: 16px;
    border: none;
    cursor: pointer;
}

.view-action-btn:hover {
    opacity: 0.9;
    text-decoration: none;
}

.page-title {
    font-size: var(--font-size-title);
    font-weight: 400;
    color: var(--color-text-dark);
    margin-bottom: 16px;
}

/* ========================================
   TOOLBAR ROW 1: Search + Copy/Paste
   ======================================== */

.toolbar-row-1 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.search-box {
    display: flex;
}

.search-input-wrapper {
    position: relative;
    display: flex;
}

.search-box input {
    width: 220px;
    height: 38px;
    padding: 8px 28px 8px 12px;
    border: 1px solid var(--color-border-btn);
    border-right: none;
    border-radius: 4px 0 0 4px;
    font-size: var(--font-size-base);
    font-family: var(--font-family);
}

.search-box input::placeholder {
    color: var(--color-text-gray);
}

.search-box input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    visibility: hidden;
}

.search-clear:hover {
    color: #333;
}

.btn-search {
    height: 38px;
    padding: 8px 16px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border-btn);
    border-radius: 0 4px 4px 0;
    color: var(--color-primary);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    cursor: pointer;
}

.btn-search:hover {
    background: var(--color-bg-header);
}

.btn-secondary {
    height: 38px;
    padding: 8px 16px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    color: var(--color-text-gray);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    cursor: pointer;
}

.btn-secondary:hover {
    background: var(--color-bg-header);
}

/* ========================================
   TOOLBAR ROW 2: Count + Actions + Pagination
   ======================================== */

.toolbar-row-2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.toolbar-row-2-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-row-2-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.entries-summary {
    font-weight: 700;
    color: var(--color-text-dark);
}

.btn-toolbar {
    height: 32px;
    padding: 6px 12px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    color: var(--color-primary);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-toolbar:hover {
    background: var(--color-bg-header);
}

.btn-icon {
    width: 36px;
    height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-save {
    background: var(--color-save-btn);
}

.btn-icon-cancel {
    background: var(--color-cancel-btn);
}

/* Done button for Jobs page */
.btn-done {
    background-color: var(--color-primary-btn);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: var(--font-size-small);
    cursor: pointer;
}

.btn-done:hover {
    opacity: 0.9;
}

.btn-delete {
    background: #fff;
    color: #dc3545;
    border-color: #dc3545;
}

.btn-delete:hover {
    background: #dc3545;
    color: #fff;
}

/* ========================================
   INLINE EDITABLE TABLE
   ======================================== */

.editable-table {
    table-layout: fixed;
    width: 100%;
}

.editable-table td,
.editable-table th {
    padding: 6px 10px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.editable-cell {
    cursor: pointer;
    transition: background-color 0.15s;
}

.editable-cell:hover {
    background-color: #f0f7ff;
}

.inline-edit {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--color-primary-btn);
    border-radius: 3px;
    font-size: var(--font-size-small);
    font-family: inherit;
    background: #fff;
    outline: none;
    box-shadow: 0 0 0 2px rgba(47, 132, 195, 0.2);
    box-sizing: border-box;
}

.inline-edit:focus {
    border-color: var(--color-primary-btn);
}

select.inline-edit {
    cursor: pointer;
}

.cell-actions {
    width: 50px;
    text-align: center;
}

.total-cell {
    font-weight: 600;
    background: var(--color-bg-alt);
}

/* ========================================
   PAGINATION
   ======================================== */

.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kn-select {
    position: relative;
}

.kn-select select {
    height: 32px;
    padding: 4px 28px 4px 10px;
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    background: var(--color-bg-white);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    appearance: none;
    cursor: pointer;
}

.kn-select::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--color-text-gray);
    pointer-events: none;
}

.pagination-text {
    color: var(--color-text);
    font-size: var(--font-size-base);
}

/* ========================================
   TOOLBAR BELOW (bottom pagination)
   ======================================== */

.toolbar-below {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

/* ========================================
   DATA TABLE
   ======================================== */

.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-base);
}

.data-table th {
    background-color: var(--color-bg-header);
    color: var(--color-text-dark);
    font-weight: 700;
    text-align: left;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
}

.data-table th a {
    color: var(--color-text-dark);
    text-decoration: none;
}

.data-table th a:hover {
    text-decoration: underline;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    background-color: #d8e2e9;
}

.data-table th .sort-icon {
    font-size: 10px;
    color: var(--color-primary);
}

.data-table td {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    vertical-align: top;
    color: var(--color-text-dark);
}

.data-table tbody tr:nth-child(even) {
    background-color: var(--color-bg-alt-row);
}

.data-table tbody tr:hover {
    background-color: #f0f0f0;
}

/* Special Columns */
.cell-checkbox {
    width: 40px;
    text-align: center;
}

.cell-edit {
    width: 50px;
    text-align: center;
}

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

.cell-currency,
.cell-number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.cell-date {
    white-space: nowrap;
}

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

/* Total Row */
.total-row {
    background-color: var(--color-bg-white) !important;
}

.total-row td {
    font-weight: 700;
}

/* ========================================
   FILTER TAGS
   ======================================== */

.filter-tag {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    gap: 6px;
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 4px;
    padding: 6px 12px;
    height: 32px;
    box-sizing: border-box;
    font-size: var(--font-size-base);
    margin-left: 8px;
    color: #1565c0;
}

.active-filters {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.filter-tag .remove {
    color: #1565c0;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
}

.filter-tag .remove:hover {
    color: #c62828;
}


/* ========================================
   FORMS
   ======================================== */

.form-group {
    margin-bottom: 16px;
}

.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.form-inline .form-group {
    min-width: 200px;
    flex: 1;
}

.form-label {
    display: block;
    margin-bottom: 4px;
    color: var(--color-text-dark);
    font-weight: 700;
    font-size: var(--font-size-base);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.btn-submit {
    background: var(--color-primary-btn);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 4px;
    font-size: var(--font-size-base);
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
}

.btn-submit:hover {
    opacity: 0.9;
}

/* ========================================
   INSTRUCTIONS PANEL
   ======================================== */

.instructions-panel {
    background: #f9f9f9;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 16px;
}

.instructions-panel h3 {
    font-size: var(--font-size-base);
    font-weight: 700;
    margin-bottom: 8px;
}

.instructions-panel p {
    margin-bottom: 4px;
    color: var(--color-text);
}

/* ========================================
   MODAL
   ======================================== */

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

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--color-bg-white);
    padding: 24px;
    border-radius: 4px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-dark);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--color-text-gray);
    cursor: pointer;
}

.modal-close:hover {
    color: var(--color-text-dark);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-gray); }
.font-bold { font-weight: 700; }

.no-data {
    text-align: center;
    padding: 20px;
    color: var(--color-text-gray);
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--color-text-gray);
}

/* ========================================
   SUMMARY CARDS (Dashboard)
   ======================================== */

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 16px;
}

.summary-card .label {
    font-size: var(--font-size-small);
    color: var(--color-text-gray);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.summary-card .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text-dark);
}

/* ========================================
   BADGES
   ======================================== */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: var(--font-size-small);
    font-weight: 600;
}

.badge-yes,
.badge-active {
    background: #d1fae5;
    color: #065f46;
}

.badge-no,
.badge-inactive {
    background: #fee2e2;
    color: #991b1b;
}

.badge-pending {
    background: #fef3c7;
    color: #92400e;
}

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

@media (max-width: 768px) {
    .app-header {
        padding: 0 10px;
    }

    .main-nav {
        overflow-x: auto;
    }

    .main-nav a {
        padding: 12px 12px;
        font-size: 14px;
    }

    .main-content {
        padding: 15px;
    }

    .toolbar-row-1,
    .toolbar-row-2 {
        flex-wrap: wrap;
    }

    .search-box input {
        width: 160px;
    }

    .user-area {
        font-size: 12px;
    }
}

/* ========================================
   LOGIN PAGE
   ======================================== */

.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 40px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.login-container h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: 8px;
    text-align: center;
}

.login-container .subtitle {
    color: var(--color-text-gray);
    text-align: center;
    margin-bottom: 32px;
}

.login-container .btn-submit {
    width: 100%;
    margin-top: 8px;
}

.login-error {
    background-color: #fee2e2;
    color: #991b1b;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    text-align: center;
}

/* ========================================
   SETTINGS PAGE
   ======================================== */

.settings-section {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-bottom: 20px;
}

.settings-section-header {
    background: var(--color-bg-header);
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    font-weight: 700;
}

.settings-section-body {
    padding: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.user-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--color-primary-btn);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}

.user-details h4 {
    font-size: 16px;
    color: var(--color-text-dark);
    margin-bottom: 4px;
}

.user-details p {
    font-size: 14px;
    color: var(--color-text-gray);
}

/* ========================================
   SECTION HEADERS (for multi-table pages)
   ======================================== */

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-dark);
    margin: 32px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

.section-description {
    color: var(--color-text-gray);
    margin-bottom: 16px;
    font-size: var(--font-size-base);
}

.section-header {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-dark);
    margin: 24px 0 16px;
}

/* ========================================
   DETAIL VIEW PAGES
   ======================================== */

/* Breadcrumb */
.breadcrumb {
    margin-bottom: 16px;
    font-size: var(--font-size-base);
}

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

.breadcrumb .separator {
    color: var(--color-text-gray);
    padding: 0 8px;
}

.breadcrumb .current {
    color: var(--color-text-dark);
}

/* Detail Actions */
.detail-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

/* Detail Section - Compact single column */
.detail-section {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 16px 20px;
    margin-bottom: 20px;
    max-width: 500px;
}

/* Detail Grid Layout (two column) */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 24px;
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 20px;
}

.detail-column {
    display: flex;
    flex-direction: column;
}

.detail-field {
    display: flex;
    align-items: baseline;
    margin-bottom: 8px;
    gap: 8px;
}

.detail-label {
    font-size: var(--font-size-small);
    color: var(--color-text-gray);
    min-width: 140px;
    flex-shrink: 0;
}

.detail-value {
    font-size: var(--font-size-base);
    color: var(--color-text-dark);
    font-weight: 600;
}

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

.detail-group-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-dark);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

/* Detail Add Actions */
.detail-add-actions {
    display: flex;
    gap: 8px;
    margin: 20px 0;
}

/* Back Link */
.back-link {
    margin-top: 24px;
    font-size: var(--font-size-base);
}

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

/* ========================================
   FILTER MODAL
   ======================================== */

.filter-modal-content {
    max-width: 900px;
    width: 95%;
}

.filters-list {
    margin-bottom: 16px;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: nowrap;
}

.filter-row .filter-label {
    font-size: var(--font-size-base);
    color: var(--color-text);
    min-width: 50px;
}

.filter-row select,
.filter-row input[type="text"],
.filter-row input[type="number"],
.filter-row input[type="date"] {
    height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
}

.filter-row select {
    min-width: 150px;
}

.filter-row .filter-value {
    flex: 1;
    min-width: 120px;
}

.filter-row .filter-remove {
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-border-btn);
    border-radius: 4px;
    background: var(--color-bg-white);
    color: var(--color-text-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-row .filter-remove:hover {
    background: var(--color-cancel-btn);
    color: var(--color-text-dark);
}

.btn-add-filter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: var(--font-size-base);
    cursor: pointer;
    padding: 4px 0;
}

.btn-add-filter:hover {
    text-decoration: underline;
}

.filter-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    margin-top: 16px;
}

.btn-cancel {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border-btn);
    padding: 8px 16px;
    border-radius: 4px;
    color: var(--color-text);
    font-size: var(--font-size-base);
    cursor: pointer;
}

.btn-cancel:hover {
    background: var(--color-bg-header);
}

/* Responsive Detail Grid */
@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}
