/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    color: #333;
    background: #f5f5f5;
}

/* Layout */
.app-container {
    display: grid;
    grid-template-columns: 250px 1fr 4px var(--preview-width, 400px);
    height: 100vh;
    gap: 0;
}

/* Sidebar */
.sidebar {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 20px;
    overflow-y: auto;
}

.sidebar h2 {
    margin-bottom: 20px;
    font-size: 18px;
}

.file-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-direction: column;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 8px;
    background: #34495e;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.file-item:hover {
    background: #445566;
}

.file-item input[type="checkbox"] {
    margin-right: 10px;
}

.file-item-info {
    flex: 1;
}

.file-item-name {
    font-weight: 500;
}

.file-item-count {
    font-size: 12px;
    color: #95a5a6;
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.search-container input {
    width: 300px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.table-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.cards-table {
    width: 100%;
    border-collapse: collapse;
}

.cards-table th {
    text-align: left;
    padding: 12px;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.cards-table td {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
}

.cards-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

.cards-table tbody tr:hover {
    background: #f8f9fa;
}

/* Tier-based row highlighting */
.cards-table tbody tr[data-card-tier="military"] {
    background: rgba(255, 200, 200, 0.3);
}

.cards-table tbody tr[data-card-tier="military"]:hover {
    background: rgba(255, 200, 200, 0.5);
}

.cards-table tbody tr[data-card-tier="king"] {
    background: rgba(220, 200, 255, 0.3);
}

.cards-table tbody tr[data-card-tier="king"]:hover {
    background: rgba(220, 200, 255, 0.5);
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px !important;
}

/* Divider */
.divider {
    background: #dee2e6;
    cursor: col-resize;
    transition: background 0.2s;
    position: relative;
}

.divider:hover {
    background: #3498db;
}

.divider.dragging {
    background: #2980b9;
}

/* Preview Panel */
.preview-panel {
    background: #f8f9fa;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.preview-panel h2 {
    margin-bottom: 20px;
    font-size: 18px;
}

.preview-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    margin-bottom: 20px;
}

.print-preview-section {
    margin-top: 20px;
}

.print-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.print-preview-header h3 {
    margin: 0;
    font-size: 16px;
    color: #2c3e50;
}

.print-preview-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.print-preview-content.hidden {
    display: none;
}

.preview-empty {
    text-align: center;
    color: #999;
    padding: 40px 0;
}

.preview-card {
    font-size: 13px;
}

.preview-section {
    margin-bottom: 20px;
}

.preview-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #2c3e50;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 4px;
}

.preview-field {
    margin-bottom: 8px;
}

.preview-label {
    font-weight: 600;
    color: #555;
}

.preview-value {
    color: #333;
}

.preview-behavior {
    background: #f8f9fa;
    padding: 10px;
    border-left: 3px solid #3498db;
    margin-bottom: 8px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

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

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    border-bottom: 1px solid #dee2e6;
    background: white;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 24px 28px;
    overflow-y: auto;
    flex: 1;
    background: #fafafa;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 28px;
    border-top: 1px solid #dee2e6;
    background: white;
}

.modal-footer .btn-danger {
    margin-right: auto;
}

/* Form */
.form-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e8e8e8;
}

.form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section h3 {
    font-size: 15px;
    margin-bottom: 16px;
    color: #2c3e50;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 12px;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 6px;
    font-weight: 500;
    color: #555;
    font-size: 13px;
}

.form-group small {
    margin-top: 4px;
    font-size: 12px;
    color: #888;
    line-height: 1.4;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    color: #333;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-group.error input,
.form-group.error select {
    border-color: #e74c3c;
    background-color: #fef5f5;
}

.form-group.warning input,
.form-group.warning select {
    border-color: #f39c12;
    background-color: #fef9f3;
}

.validation-error {
    background-color: #fef5f5;
    border-left: 3px solid #e74c3c;
}

.validation-warning {
    background-color: #fef9f3;
    border-left: 3px solid #f39c12;
}

.btn-warning {
    background: #f39c12;
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
}

/* Behavior Editor */
#behaviors-container {
    margin-bottom: 12px;
}

.behavior-item {
    background: white;
    padding: 16px;
    border-radius: 6px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.behavior-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.behavior-header h4 {
    font-size: 13px;
    color: #2c3e50;
    font-weight: 600;
}

.behavior-fields {
    display: grid;
    gap: 12px;
}

.args-editor {
    margin-top: 0;
}

.args-editor textarea {
    width: 100%;
    min-height: 80px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.args-hint {
    display: block;
    white-space: pre-line;
}

/* Table Column Widths */
.cards-table .col-uid {
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cards-table .col-name {
    min-width: 120px;
}

.cards-table .col-type {
    width: 90px;
}

.cards-table .col-strike {
    width: 80px;
    white-space: nowrap;
}

.cards-table .col-defense {
    width: 100px;
    white-space: nowrap;
}

.cards-table .col-cost {
    width: 70px;
    white-space: nowrap;
}

.cards-table .col-produce {
    width: 70px;
    white-space: nowrap;
}

.cards-table .col-actions {
    width: 80px;
    text-align: center;
}

/* Utility */
.strike-vector {
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-unit { background: #3498db; color: white; }
.badge-tower { background: #e67e22; color: white; }
.badge-wall { background: #95a5a6; color: white; }
.badge-structure { background: #9b59b6; color: white; }
.badge-building { background: #1abc9c; color: white; }

/* Image Editor */
.image-editor-container {
    margin-top: 12px;
}

.image-editor {
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    background: white;
}

.image-viewport {
    width: 100%;
    height: 240px;
    background: #f8f8f8;
    border-bottom: 1px solid #ddd;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

.image-viewport:active {
    cursor: grabbing;
}

.image-viewport img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center;
    user-select: none;
}

.image-controls {
    padding: 12px;
    background: white;
    display: flex;
    align-items: center;
    gap: 10px;
}

.image-controls label {
    margin: 0;
    font-weight: 500;
    font-size: 13px;
    color: #555;
}

.image-controls input[type="range"] {
    flex: 1;
}

.image-controls #zoom-value {
    min-width: 50px;
    text-align: center;
    font-weight: 500;
    font-size: 13px;
    color: #555;
}
